Skip to content

Commit adccdff

Browse files
committed
支持Long,Double,主键字符串的推测。
1 parent 0e53763 commit adccdff

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

Entities/EntityInferContext.vb

+31-7
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,32 @@ Public Class EntityInferContext
5050
Where tp.PropertyBasicInformation.Name = basicInformation.Name
5151
Into FirstOrDefault
5252
If initExpr IsNot Nothing Then
53-
initExpr.InitialValue = initExpr.InitialValue.Replace("""", "")
54-
If initExpr.InitialValue.Contains(",") Then
55-
initExpr.PropertyBasicInformation.IsQueryable = True
56-
ElseIf ClassIndex.ContainsKey(initExpr.InitialValue) Then
57-
initExpr.PropertyBasicInformation.TypeNameOverride = ClassIndex(initExpr.InitialValue)
53+
Dim init = initExpr.InitialValue
54+
If init.StartsWith("""") AndAlso init.EndsWith("""") Then
55+
initExpr.InitialValue = init.Substring(1, init.Length - 2)
56+
If initExpr.InitialValue.Contains(",") Then
57+
initExpr.PropertyBasicInformation.IsQueryable = True
58+
ElseIf ClassIndex.ContainsKey(initExpr.InitialValue) Then
59+
Dim refCls = ClassIndex(initExpr.InitialValue)
60+
If refCls Is cls Then
61+
initExpr.InitialValue = init
62+
initExpr.PropertyBasicInformation.TypeNameOverride = Nothing
63+
Else
64+
initExpr.PropertyBasicInformation.TypeNameOverride = refCls
65+
End If
66+
End If
67+
Else
68+
initExpr.InitialValue = $"{NamespaceBuilder.Name}Context.{initExpr.PropertyBasicInformation.RuntimeTypeName}.Find({init})"
5869
End If
5970
End If
6071
End If
6172
'删除多余的属性定义
6273
curProperties.Remove(curKey)
74+
Else
75+
If prop.Value.IsPrimaryKey Then
76+
Dim baseProp = prop.Value
77+
cls.BasePropertyInitialization.Add(New VBPropertyAssignmentDeclaration(baseProp.BasicInformation, SurroundInitExpr(cls.Name, "String")))
78+
End If
6379
End If
6480
Next
6581
Else
@@ -270,8 +286,16 @@ Public Class EntityInferContext
270286
Return """" + initValue + """"
271287
Case "Guid"
272288
Return $"New {typeName}(""{initValue}"")"
273-
Case "Percentage"
274-
Return $"Percentage.Parse(""{initValue}"")"
289+
Case "Percentage", "BigInteger"
290+
Return $"{typeName}.Parse(""{initValue}"")"
291+
Case "Single"
292+
Return initValue & "F"
293+
Case "Long"
294+
Return initValue & "L"
295+
Case "ULong"
296+
Return initValue & "UL"
297+
Case "Decimal"
298+
Return initValue & "D"
275299
Case Else
276300
Return initValue
277301
End Select

Entities/VBNamespaceBuilder.vb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Imports System.Text
22

33
Public Class VBNamespaceBuilder
4-
Dim name As String
4+
Public Property Name As String
55
Sub New(sb As IndentStringBuilder, name$)
66
Me.sb = sb
7-
Me.name = name
7+
Me.Name = name
88
End Sub
99

1010
Public Sub BeginBlock()
11-
sb.IndentAppend("Namespace ").AppendLine(name).IncreaseIndent()
11+
sb.IndentAppend("Namespace ").AppendLine(Name).IncreaseIndent()
1212
End Sub
1313

1414
Friend sb As IndentStringBuilder

Help/HelpDataProvider.vb

+33-7
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,25 @@ Public Class HelpDataProvider
163163
Dim spa = rig.Split(","c)
164164
Dim sp = spa.First.Trim
165165
If sp.IsInteger Then
166-
For Each tp In spa
166+
For Each tp In spa.Skip(1)
167167
If Not tp.Trim.IsInteger Then Return "IEnumerable(Of String)"
168168
Next
169-
Return "IEnumerable(Of Integer)"
169+
Return $"IEnumerable(Of {FilterIntegerTypes(sp)})"
170170
ElseIf sp.IsFraction Then
171-
172-
For Each tp In spa
171+
For Each tp In spa.Skip(1)
173172
If Not tp.Trim.IsFraction Then Return "IEnumerable(Of String)"
174173
Next
175-
Return "IEnumerable(Of Single)"
174+
Return $"IEnumerable(Of {FilterFractionTypes(sp)})"
176175
ElseIf sp.Replace("%", "").IsInteger Then
177176
Return "IEnumerable(Of Percentage)"
178177
Else
179178
Return "IEnumerable(Of String)"
180179
End If
181180
Else
182181
If rig.IsInteger Then
183-
Return "Integer"
182+
Return FilterIntegerTypes(rig)
184183
ElseIf rig.IsFraction Then
185-
Return "Single"
184+
Return FilterFractionTypes(rig)
186185
ElseIf {"true", "false", "yes", "no"}.Contains(rig.ToLowerInvariant) Then
187186
Return "Boolean"
188187
ElseIf rig.Replace("%", "").IsInteger Then
@@ -195,4 +194,31 @@ Public Class HelpDataProvider
195194
End If
196195
End Function
197196

197+
Private Shared Function FilterFractionTypes(rig As String) As String
198+
Dim sng = 0F, dbl = 0#, dec = 0D
199+
If Single.TryParse(rig, sng) AndAlso Double.TryParse(rig, dbl) AndAlso Decimal.TryParse(rig, dec) Then
200+
Dim sdbl = dbl.ToString
201+
If sdbl = sng.ToString Then
202+
Return "Single"
203+
ElseIf dec.ToString = sdbl Then
204+
Return "Double"
205+
Else
206+
Return "Decimal"
207+
End If
208+
Else
209+
Return "String"
210+
End If
211+
End Function
212+
213+
Private Shared Function FilterIntegerTypes(rig As String) As String
214+
If Integer.TryParse(rig, 0) Then
215+
Return "Integer"
216+
ElseIf Long.TryParse(rig, 0) Then
217+
Return "Long"
218+
ElseIf ULong.TryParse(rig, 0) Then
219+
Return "ULong"
220+
Else
221+
Return "String"
222+
End If
223+
End Function
198224
End Class

0 commit comments

Comments
 (0)