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.NotContainsmethod, so creating a call to a method calledNotContainsdoesn’t work.A simple solution is to combine the
notoperator, with theContainsmethod. Just like normally you’d write!x.Contains(y)and notx.NotContains(y).To create such an expression you can use
Expression.Not(callExpression).