Skip to content
AlbertoMonteiro edited this page Jun 16, 2011 · 12 revisions

Welcome to the DynamicExpressionBuilder wiki!

public class Person { public string Name { get; set; } public int Age { get; set; } public bool HasCar { get; set; } }

main() { List persons = new List { new Person {Name = "Alberto",Age = 21, HasCar = False}, new Person {Name = "Pedro",Age = 26, HasCar = True } };

//I want only peoples that has car, and has 'o' on the name
var filter = new FilterExpression<Pessoa>();
filter.Start(p => p.Name.Contains("o")).And(p => p.HasCar);
foreach(var item in persons.Where(filter.ResultExpression))
    Console.WriteLine(item.Name);
//Or
var filter2 = new FilterExpression<Pessoa>();
filter2 = filter2.Start(p => p.Name.Contains("o"));
filter2 = filter2.And(p => p.HasCar);    
foreach(var item in persons.Where(filter2.ResultExpression))
    Console.WriteLine(item.Name);

}

Clone this wiki locally