using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; public class Test { public static void Main() { var parameter = Expression.Parameter(typeof(Answer), "a"); var answers = new List { new Answer { Property1 = "foo", Property2 = "bar" }, new Answer { Property1 = "foo", Property2 = "baz" }, }; for (var i = 1; i <= 2; ++i) { var propertyValue = Expression.MakeMemberAccess(parameter, typeof(Answer).GetProperty("Property" + i)); var predicate = Expression.Equal(propertyValue, Expression.Constant("foo")); var lambda = (Func)Expression.Lambda(predicate, parameter).Compile(); Console.WriteLine("Searching Property" + i + " for the value 'foo':"); foreach (var a in answers.Where(lambda)) { Console.WriteLine(a); } } } } class Answer { public string Property1 { get; set; } public string Property2 { get; set; } public override string ToString() { return string.Format("{0} {1}", Property1, Property2); } }