jeriley
jeriley

Reputation: 1333

Lambda expression -- apply logical not to a boolean method call

This must have a simple answer -- I have a piece of code that looks like this ...

condition = Expression.Call(memberAccess,
                        typeof(string).GetMethod("Contains"),
                        Expression.Constant(value));
                    lambda = Expression.Lambda(condition, parameter);

it works great ... BUT I also want a NotContains. Am I going to have to write an extension method or is there a way to simply do a ![lambda] ?

Upvotes: 2

Views: 970

Answers (1)

Kirk Woll
Kirk Woll

Reputation: 77546

Surround with Expression.Not:

condition = Expression.Not(Expression.Call(memberAccess,
                    typeof(string).GetMethod("Contains"),
                    Expression.Constant(value)));
lambda = Expression.Lambda(condition, parameter);

Upvotes: 9

Related Questions