f6b4108e55e2b1d26692c02848742689f57daf46
[platform/upstream/dotnet/runtime.git] /
1 ' Licensed to the .NET Foundation under one or more agreements.
2 ' The .NET Foundation licenses this file to you under the MIT license.
3 ' See the LICENSE file in the project root for more information.
4
5 Imports System
6 Imports Microsoft.VisualBasic.CompilerServices.Utils
7
8 Namespace Microsoft.VisualBasic.CompilerServices
9
10     <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
11     Public NotInheritable Class CharArrayType
12         ' Prevent creation.
13         Private Sub New()
14         End Sub
15
16         Public Shared Function FromString(ByVal Value As String) As Char()
17
18             If Value Is Nothing Then
19                 Value = ""
20             End If
21
22             Return Value.ToCharArray()
23
24         End Function
25
26         Public Shared Function FromObject(ByVal Value As Object) As Char()
27
28             If Value Is Nothing Then
29                 Return "".ToCharArray()
30             End If
31
32             Dim CharArray As Char() = TryCast(Value, Char())
33
34             If CharArray IsNot Nothing AndAlso CharArray.Rank = 1 Then
35                 Return CharArray
36
37             Else
38                 Dim ValueInterface As IConvertible
39                 ValueInterface = TryCast(Value, IConvertible)
40
41                 If Not ValueInterface Is Nothing Then
42                     If (ValueInterface.GetTypeCode() = TypeCode.String) Then
43                         Return ValueInterface.ToString(Nothing).ToCharArray()
44                     End If
45                 End If
46
47             End If
48
49             Throw New InvalidCastException(SR.Format(SR.InvalidCast_FromTo, VBFriendlyName(Value), "Char()"))
50
51         End Function
52
53     End Class
54
55 End Namespace
56
57