Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

lambda

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] ?

like image 374
jeriley Avatar asked Apr 17 '26 02:04

jeriley


1 Answers

Surround with Expression.Not:

condition = Expression.Not(Expression.Call(memberAccess,
                    typeof(string).GetMethod("Contains"),
                    Expression.Constant(value)));
lambda = Expression.Lambda(condition, parameter);
like image 129
Kirk Woll Avatar answered Apr 19 '26 15:04

Kirk Woll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!