0

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.

ckittel
  • 6,478
  • 3
  • 41
  • 71
mr.moe
  • 75
  • 4
  • You cannot use `System.Nullable(Of T).Equals` in the way that you are attempting: the code that you want to generate is invalid – no wonder that the generator refuses to generate that code. – Konrad Rudolph Mar 29 '11 at 12:09
  • That's why I'm searching a way to generate the Nullable.Equals function through a CodeConditionStatement that is working :D – mr.moe Mar 29 '11 at 12:33
  • That won’t work either. The code you want to call simply doesn’t exist. `Nullable` isn’t a complete class, it needs to be `Nullable(Of SomeType)`. – Konrad Rudolph Mar 29 '11 at 12:34

1 Answers1

0

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

mr.moe
  • 75
  • 4