Lambda and Expression.Call for an extension method

前端 未结 5 950
野趣味
野趣味 2021-01-17 23:08

I need to implement an expression for a method like here:

var prop = Expression.Property(someItem, \"Name\"); 
var value = Expression.Constant(someConstant);         


        
5条回答
  •  鱼传尺愫
    2021-01-17 23:25

    You can do like this:

    var like = typeof(StringEx).GetMethod("Like", new[] {typeof(string), typeof(string)});
    
    comparer = Expression.Call(null, like, prop, value);
    

    You can pass prop as first parameter and value as second parameter like above.

    Maybe you will need to get a complete query before apply an extension method.

提交回复
热议问题