I created a filterable BindingList from this source: http://www.nablasoft.com/alkampfer/index.php/2008/11/22/extend-bindinglist-with-filter-functionality/
It works great (
list.Filter("Customer == 'Name'");
does what it should. In the internals works a parser, that converts the expression "==" or "!=" into "System.Linq.Expressions.Expression", in this case (==) :
System.Linq.Expressions.Expression.Equal
Unfortunatly System.Linq.Expressions.Expression does not contain a like operator. But I am to much beginner with linq and I don't know how to solve this.
The initial code looks like this:
private static Dictionary<String, Func<Expression, Expression, Expression>>
binaryOpFactory = new Dictionary<String, Func<Expression, Expression, Expression>> ();
static Init() {
binaryOpFactory.Add("==", Expression.Equal);
binaryOpFactory.Add(">", Expression.GreaterThan);
binaryOpFactory.Add("<", Expression.LessThan);
binaryOpFactory.Add(">=", Expression.GreaterThanOrEqual);
binaryOpFactory.Add("<=", Expression.LessThanOrEqual);
binaryOpFactory.Add("!=", Expression.NotEqual);
binaryOpFactory.Add("&&", Expression.And);
binaryOpFactory.Add("||", Expression.Or);
}
Now I created an expression, that will do what I want:
private static System.Linq.Expressions.Expression<Func<String, String, bool>>
Like_Lambda = (item, search) => item.ToLower().Contains(search.ToLower());
private static Func<String, String, bool> Like = Like_Lambda.Compile();
e.g.
Console.WriteLine(like("McDonalds", "donAld")); // true
Console.WriteLine(like("McDonalds", "King")); // false
But the binaryOpFactory requires this
Func<Expression, Expression, Expression>
The predefined expressions seem to be exactly that:
System.Linq.Expressions.Expression.Or;
Can anyone tell me howto convert my expression?