有没有办法强制 VB.Net 匿名类型的 属性 类型?
Is there a way to force the type of a property of a VB.Net anonymous type?
我的意思是这样的(粗体):
Dim anonType = New With {.Property1 = 10, .Property2 As Decimal? = Nothing}
你总是可以像这样解决它..
Private Sub test()
Dim tempDecimal? As Decimal = Nothing
Dim anonType = New With {.Property1 = 10, .Property2 = tempDecimal}
' property value is nothing here, but if tempDecimal isnt declared as nullable,
'the value will be 0
anonType.property2 = Nothing
anonType.property2 = 5
'tp will be Decimal here
Dim tp As Type = anonType.property2.GetType
End Sub
我的意思是这样的(粗体):
Dim anonType = New With {.Property1 = 10, .Property2 As Decimal? = Nothing}
你总是可以像这样解决它..
Private Sub test()
Dim tempDecimal? As Decimal = Nothing
Dim anonType = New With {.Property1 = 10, .Property2 = tempDecimal}
' property value is nothing here, but if tempDecimal isnt declared as nullable,
'the value will be 0
anonType.property2 = Nothing
anonType.property2 = 5
'tp will be Decimal here
Dim tp As Type = anonType.property2.GetType
End Sub