[英]CodeConditionStatement and Nullable.Equals
我必須通過C#CodeConditionStatement創建以下VB.Net代碼
If Not Nullable.Equals(field.Name, Value) Then
...
End If
我曾嘗試過的是
var property = new CodeMemberProperty();
CodeExpression condition = new CodeMethodInvokeExpression(System.Nullable,"Equals", new CodeExpression(){
new CodeVariableReferenceExpression(field.Name),
new CodePropertySetValueReferenceExpression()
});
property.SetStatements.Add(new CodeConditionStatement(condition, null));
但是System.Nullable
不能在CodeExpression中轉換。
所以這似乎可行:
property.SetStatements.Add(new CodeConditionStatement(
new CodeSnippetExpression(String.Format("Not Nullable.Equals({0}, value)", field.Name)),
null));
很糟糕,但是工作.....
如果有人有更好的主意:D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.