I need to implement an expression for a method similar here:
var prop = Expression.Property(someItem, "Name");
var value = Expression.Constant(someConstant);
var contains = typeof(string).GetMethod("Contains", new[] {typeof(string)});
var expression = Expression.Call(prop, contains, value);
But for my extension method:
public static class StringEx
{
public static bool Like(this string a, string b)
{
return a.ToLower().Contains(b.ToLower());
}
}
Unfortunately, the following code throws an ArgumentNullException for the method parameter:
var like = typeof(string).GetMethod("Like", new[] {typeof(string)});
comparer = Expression.Call(prop, like, value);
What am I doing wrong?
source
share