views:

56

answers:

1

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.

Any suggestions?

Thanks.

+6  A: 

What about Expression.Not? That would simply be:

var condition = Expression.Not (contains_call);
Jb Evain
That's the one. Thanks!
Marcus