StackOverflowVeryHelpful StackOverflowVeryHelpful -3 years ago 140
C# Question

Build expression trees to represent if-else

Deserializing of Expression tree using ExpressionSerialization on a full conditional expression i.e ternary operator is giving error . If i am using ternary operator it causes FullConditionExpression (System Not Supported Exception)

Using code from following links:

Are there any latest version available for the above link?

Tried this afterwards

public Expression<Func<object, string>> LabelCriteria { get; set; }

LabelCriteria = x =>
if (true)
return "Cash";
return " ";

Expression doesn't support if - else block . It gives error as " A lambda expression with a statement body cannot be converted to expression tree . Is there any other way to do it.

Answer Source

You could use a method like here:

string myFunction(Object obj){
     //here your if-else...

LabelCriteria = x => myFunction(x);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download