CodeConditionStatement和Nullable.Equals

时间:2011-03-29 12:02:20

标签: vb.net code-generation dblinq dbmetal

我必须通过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));

但无法在CodeExpression中转换System.Nullable

1 个答案:

答案 0 :(得分:0)

所以这似乎有效:

property.SetStatements.Add(new CodeConditionStatement(
                new CodeSnippetExpression(String.Format("Not Nullable.Equals({0}, value)", field.Name)), 
                null));

非常糟糕但工作......

如果有人有更好的主意:D