KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I created a filterable BindingList from this source . It works great: list.Filter("Customer == 'Name'"); does what it should. The internals work like a parser, that converts the expression == or != into System.Linq.Expressions.Expression . In this case, == becomes System.Linq.Expressions.Expression.Equal . Unfortunately System.Linq.Expressions.Expression does not contain a like operator 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); } Then 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 binaryOpFactory requires this: Func<Expression, Expression, Express
Tags (comma-separated)
Save Edits
Cancel