"Does Not Contain" dynamic lambda expression

The code below does "Contain" expression:

private static Expression<Func<T, bool>> Contains<T>(string property, string value)
{
    var obj = Expression.Parameter(typeof(T), "obj");
    var objProperty = Expression.PropertyOrField(obj, property);
    var contains = Expression.Call(objProperty, "Contains", null, Expression.Constant(value, typeof(string)));
    var lambda = Expression.Lambda<Func<T, bool>>(contains, obj);
    return lambda;
}

I am not very familiar with Expressions and I don't know how to put negation into the expression function and cannot find any suitable method in "Expression" class. Is there any similar way to create "Does Not Contain" expression dynamically?

Jon Skeet
people
quotationmark

A "does not contain" expression is exactly the same as a "does contain" expression - but wrapped with a unary negation expression. So basically you want:

// Code as before
var doesNotContain = Expression.Not(contains);
return Expression.Lambda<Func<T, bool>>(doesNotContain, obj);

people

See more on this question at Stackoverflow