开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜