recently I’ve been working with the PredicateBuilder class (shown here) to help generate an expression tree. The True, And, and Or methods provided work fine. However, I would also like to use a Not method, and so far my attempt at one gets me the error
Incorrect number of parameters supplied for lambda declaration.
Here is said attempt:
public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> expr)
{
return Expression.Lambda<Func<T, bool>>
(Expression.Not(Expression.Invoke(expr, expr.Parameters.Cast<Expression>())));
}
Any thoughts?
NB
Oop, just about had it. I wasn’t giving parameters to the outer .Lambda function: