1 |
#Region "Microsoft.VisualBasic::fb8beac19d7d95ce23104c8e5b978a72, Microsoft.VisualBasic.Core\Scripting\Runtime\CType\CastStringVector.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
#End Region
|
43 |
|
44 |
Imports System.Drawing
|
45 |
Imports System.Runtime.CompilerServices
|
46 |
Imports Microsoft.VisualBasic.Linq
|
47 |
|
48 |
Namespace Scripting.Runtime
|
49 |
|
50 |
Public Module CastStringVector
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
58 |
<Extension>
|
59 |
Public Function AsCharacter(values As Dictionary(Of String, Double)) As Dictionary(Of String, String)
|
60 |
Return values.ToDictionary(
|
61 |
Function(x) x.Key,
|
62 |
Function(x) CStr(x.Value))
|
63 |
End Function
|
64 |
|
65 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
66 |
<Extension>
|
67 |
Public Function AsCharacter(values As IEnumerable(Of Double), Optional negPrefix As Boolean = False, Optional format$ = "G4") As IEnumerable(Of String)
|
68 |
Return values _
|
69 |
.SafeQuery _
|
70 |
.Select(Function(d)
|
71 |
If d > 0 AndAlso negPrefix Then
|
72 |
Return " " & d.ToString(format)
|
73 |
Else
|
74 |
Return d.ToString(format)
|
75 |
End If
|
76 |
End Function)
|
77 |
End Function
|
78 |
|
79 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
80 |
<Extension>
|
81 |
Public Function AsCharacter(Of T)(values As IEnumerable(Of T), Optional null$ = "") As IEnumerable(Of String)
|
82 |
Return values.SafeQuery.Select(Function(o) Scripting.ToString(o, null))
|
83 |
End Function
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
91 |
<Extension>
|
92 |
Public Function AsNumeric(values As Dictionary(Of String, String)) As Dictionary(Of String, Double)
|
93 |
Return values.ToDictionary(
|
94 |
Function(x) x.Key,
|
95 |
Function(x) x.Value.ParseNumeric)
|
96 |
End Function
|
97 |
|
98 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
99 |
<Extension>
|
100 |
Public Function AsGeneric(Of T)(values As Dictionary(Of String, T)) As Dictionary(Of String, Object)
|
101 |
Return values.ToDictionary(
|
102 |
Function(x) x.Key,
|
103 |
Function(x) CObj(x.Value))
|
104 |
End Function
|
105 |
|
106 |
<Extension> Public Function AsType(Of T)(source As IEnumerable(Of String)) As IEnumerable(Of T)
|
107 |
Dim type As Type = GetType(T)
|
108 |
Dim [ctype] = InputHandler.CasterString(type)
|
109 |
Dim result = source.Select(Function(x) DirectCast([ctype](x), T))
|
110 |
Return result
|
111 |
End Function
|
112 |
|
113 |
<Extension>
|
114 |
Public Function AsDouble(source As IEnumerable(Of String)) As Double()
|
115 |
Return source.AsType(Of Double).ToArray
|
116 |
End Function
|
117 |
|
118 |
<Extension>
|
119 |
Public Function AsNumeric(source As IEnumerable(Of String)) As Double()
|
120 |
Return source _
|
121 |
.Select(Function(s) s.ParseNumeric) _
|
122 |
.ToArray
|
123 |
End Function
|
124 |
|
125 |
<Extension>
|
126 |
Public Function AsDouble(singles As IEnumerable(Of Single)) As Double()
|
127 |
Return singles _
|
128 |
.SafeQuery _
|
129 |
.Select(Function(s) CDbl(s)) _
|
130 |
.ToArray
|
131 |
End Function
|
132 |
|
133 |
<Extension>
|
134 |
Public Function AsSingle(source As IEnumerable(Of String)) As Single()
|
135 |
Return source.AsType(Of Single).ToArray
|
136 |
End Function
|
137 |
|
138 |
<Extension>
|
139 |
Public Function AsBoolean(source As IEnumerable(Of String)) As Boolean()
|
140 |
Return source.AsType(Of Boolean).ToArray
|
141 |
End Function
|
142 |
|
143 |
<Extension>
|
144 |
Public Function AsInteger(source As IEnumerable(Of String)) As Integer()
|
145 |
Return source.AsType(Of Integer).ToArray
|
146 |
End Function
|
147 |
|
148 |
<Extension>
|
149 |
Public Function AsColor(source As IEnumerable(Of String)) As Color()
|
150 |
Return source.AsType(Of Color).ToArray
|
151 |
End Function
|
152 |
End Module
|
153 |
End Namespace
|