문제

I have to create the following VB.Net code through a C# CodeConditionStatement

If Not Nullable.Equals(field.Name, Value) Then
    ...
End If

What I alredy tried was

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));

but a System.Nullable can't be converted in a CodeExpression.

도움이 되었습니까?

해결책

So this seems to work:

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

pretty awful but working.....

If someone has a better idea :D

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top