Lambda expression for Contains
operator I am able to generate using this code.
Expression
Company => Company.Name.Contains("test1")
Source code
var method = typeof(string).GetMethod("Contains", new[] { typeof(string) });
var startsWithDishExpr = Expression.Call(argLeft, method, argRight);
Its working fine for Contains
operator.
How to modify to code to work for NotContains
operator.
Source code
var method = typeof(string).GetMethod("NotContains", new[] { typeof(string) });
var startsWithDishExpr = Expression.Call(argLeft, method, argRight);
NotContains
operator not working. Anybody have suggestion?
There is no string.NotContains
method, so creating a call to a method called NotContains
doesn't work.
A simple solution is to combine the not
operator, with the Contains
method. Just like normally you'd write !x.Contains(y)
and not x.NotContains(y)
.
To create such an expression you can use Expression.Not(callExpression)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With