1
我在我的發生器中有這個功能。如何使用CodeDom創建一個十進制常量?
Private Sub AddBoundedValue(ByVal boundedValue As Object, ByVal type As CodeTypeDeclaration, ByVal numericType As Type, name As String)
If boundedValue IsNot Nothing Then
Dim constant As New CodeMemberField(numericType, name)
constant.Attributes = MemberAttributes.Const Or MemberAttributes.Public
constant.InitExpression = New CodePrimitiveExpression(Convert.ChangeType(boundedValue, numericType))
type.Members.Add(constant)
End If
End Sub
如果顯影劑通過在用於「一個BoundedValue」參數和小數類型爲「numericType」十進制參數下面的代碼獲取生成。
Public Const DollarAmountMaximumValue As Decimal = 100000
儘管數據類型在通入CodePrimitiveExpression對象是一個小數的構造,生成的代碼是獲取隱式轉換並存儲在一個十進制可變的整數。有什麼辦法得到它與數後的「d」產生如:
Public Const DollarAmountMaximumValue As Decimal = 100000D
感謝。