forked from efcore/EFCore.VisualBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualBasicUtilities.vb
More file actions
297 lines (268 loc) · 7.84 KB
/
Copy pathVisualBasicUtilities.vb
File metadata and controls
297 lines (268 loc) · 7.84 KB
1
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
Imports System.Globalization
Imports Microsoft.EntityFrameworkCore.Diagnostics
Imports CA = System.Diagnostics.CodeAnalysis
Public Module VisualBasicUtilities
Private ReadOnly _keywords As IReadOnlyCollection(Of String) =
{
"AddHandler",
"AddressOf",
"Alias",
"And",
"AndAlso",
"As",
"Boolean",
"ByRef",
"Byte",
"ByVal",
"Call",
"Case",
"Catch",
"CBool",
"CByte",
"CChar",
"CDate",
"CDbl",
"CDec",
"Char",
"CInt",
"Class",
"CLng",
"CObj",
"Const",
"Continue",
"CSByte",
"CShort",
"CSng",
"CStr",
"CType",
"CUInt",
"CULng",
"CUShort",
"Date",
"Decimal",
"Declare",
"Default",
"Delegate",
"Dim",
"DirectCast",
"Do",
"Double",
"Each",
"Else",
"ElseIf",
"End",
"EndIf",
"Enum",
"Erase",
"Error",
"Event",
"Exit",
"False",
"Finally",
"For",
"Friend",
"Function",
"Get",
"GetType",
"GetXMLNamespace",
"Global",
"GoSub",
"GoTo",
"Handles",
"If",
"Implements",
"Imports",
"In",
"Inherits",
"Integer",
"Interface",
"Is",
"IsNot",
"Let",
"Lib",
"Like",
"Long",
"Loop",
"Me",
"Mod",
"Module",
"MustInherit",
"MustOverride",
"MyBase",
"MyClass",
"NameOf",
"Namespace",
"Narrowing",
"New",
"Next",
"Not",
"Nothing",
"NotInheritable",
"NotOverridable",
"Object",
"Of",
"On",
"Operator",
"Option",
"Optional",
"Or",
"OrElse",
"Overloads",
"Overridable",
"Overrides",
"ParamArray",
"Partial",
"Private",
"Property",
"Protected",
"Public",
"RaiseEvent",
"ReadOnly",
"ReDim",
"REM",
"RemoveHandler",
"Resume",
"Return",
"SByte",
"Select",
"Set",
"Shadows",
"Shared",
"Short",
"Single",
"Static",
"Step",
"Stop",
"String",
"Structure",
"Sub",
"SyncLock",
"Then",
"Throw",
"To",
"True",
"Try",
"TryCast",
"TypeOf",
"UInteger",
"ULong",
"UShort",
"Using",
"Variant",
"Wend",
"When",
"While",
"Widening",
"With",
"WithEvents",
"WriteOnly",
"Xor"
}
Friend ReadOnly _builtInTypeNames As IReadOnlyDictionary(Of Type, String) = New Dictionary(Of Type, String) From
{
{GetType(Boolean), "Boolean"},
{GetType(Byte), "Byte"},
{GetType(SByte), "SByte"},
{GetType(Char), "Char"},
{GetType(Short), "Short"},
{GetType(Integer), "Integer"},
{GetType(Long), "Long"},
{GetType(UShort), "UShort"},
{GetType(UInteger), "UInteger"},
{GetType(ULong), "ULong"},
{GetType(Decimal), "Decimal"},
{GetType(Single), "Single"},
{GetType(Double), "Double"},
{GetType(String), "String"},
{GetType(Date), "Date"},
{GetType(Object), "Object"}
}
Public Function IsVisualBasicKeyword(identifier As String) As Boolean
Return _keywords.Contains(identifier, StringComparer.OrdinalIgnoreCase)
End Function
Public Function IsIdentifierStartCharacter(ch As Char) As Boolean
If ch < "a"c Then
If ch < "A"c Then
Return False
End If
Return ch <= "Z"c OrElse ch = "_"c
End If
If ch <= "z"c Then
Return True
End If
If ch <= Convert.ToChar(&H7F) Then 'max ASCII
Return False
End If
Return IsLetterChar(CharUnicodeInfo.GetUnicodeCategory(ch))
End Function
Public Function IsIdentifierPartCharacter(ch As Char) As Boolean
If ch < "a"c Then
If ch < "A"c Then
Return ch >= "0"c AndAlso ch <= "9"c
End If
Return ch <= "Z"c OrElse ch = "_"c
End If
If ch <= "z"c Then
Return True
End If
If ch <= Convert.ToChar(&H7F) Then 'max ASCII
Return False
End If
Dim category = CharUnicodeInfo.GetUnicodeCategory(ch)
If IsLetterChar(category) Then
Return True
End If
Return category = UnicodeCategory.DecimalDigitNumber OrElse
category = UnicodeCategory.ConnectorPunctuation OrElse
category = UnicodeCategory.NonSpacingMark OrElse
category = UnicodeCategory.SpacingCombiningMark OrElse
category = UnicodeCategory.Format
End Function
Public Function IsLetterChar(category As UnicodeCategory) As Boolean
Return category = UnicodeCategory.UppercaseLetter OrElse
category = UnicodeCategory.LowercaseLetter OrElse
category = UnicodeCategory.TitlecaseLetter OrElse
category = UnicodeCategory.ModifierLetter OrElse
category = UnicodeCategory.OtherLetter OrElse
category = UnicodeCategory.LetterNumber
End Function
#Region "Guards"
<DebuggerStepThrough>
Public Function NotNull(Of T)(value As T, parameterName As String) As T
If value Is Nothing Then
Throw New ArgumentNullException(parameterName)
End If
Return value
End Function
<DebuggerStepThrough>
Public Function NotEmpty(Of T)(value As IReadOnlyList(Of T), parameterName As String) As IReadOnlyList(Of T)
NotNull(value, parameterName)
If Not value.Any() Then
Throw New ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(parameterName))
End If
Return value
End Function
<DebuggerStepThrough>
Public Function NotEmpty(value As String, parameterName As String) As String
NotNull(value, parameterName)
If String.IsNullOrWhiteSpace(value) Then
Throw New ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName))
End If
Return value
End Function
<DebuggerStepThrough>
Public Function NullButNotEmpty(value As String, parameterName As String) As String
If value IsNot Nothing AndAlso value.Length = 0 Then
NotEmpty(parameterName, NameOf(parameterName))
Throw New ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName))
End If
Return value
End Function
<Conditional("DEBUG")>
Public Sub DebugAssert(<CA.DoesNotReturnIf(False)> condition As Boolean, message As String)
If Not condition Then
Throw New Exception($"Check.DebugAssert failed: {message}")
End If
End Sub
#End Region
End Module