Negating a method call in an Expression tree
I'm generating a c# Linq expression dynamically as below, which will (in the example below) run string.Contains against the collection values.
var dynamicMethod = "Contains";
var parameter = Expression.Parameter(typeof (MyClass), "type");
var property = Expression.Property(parameter, "MyProperty");
var constantValue = Expression.Constant("PropertyValue", property.Type);
var method = property.Type.GetMethod(dynamicMethod, new[] {property.Type});
var expression = Expression.Call(property, method, constantValue);
For the above code, I'd want something equivalent to !Contains.
A开发者_如何学JAVAny suggestions?
Thanks.
What about Expression.Not? That would simply be:
var condition = Expression.Not (contains_call);
精彩评论