A library that provides a simple way to create lambda expressions to filter lists and database queries.
var filter = new Filter<Person>(); filter.By("Id", Operation.Between, 2, 4, Connector.And); filter.By("Contacts[Value]", Operation.EndsWith, "@email.com", default(string), Connector.And); filter.By("Birth.Country", Operation.IsNotNull, default(string), default(string), Connector.Or); filter.By("Name", Operation.Contains, " John"); var people = People.Where(filter); //or like this... var filter = new Filter<Person>(); filter.By("Id", Operation.Between, 2, 4) .And.By("Birth.Country", Operation.IsNotNull) .And.By("Contacts[Value]", Operation.EndsWith, "@email.com") .Or.By("Name", Operation.Contains, " John "); var people = People.Where(filter);
So that would generate an expression like this:
People.Where(p => (p.Id >= 2 && p.Id <= 4) && (p.Birth != null && p.Birth.Country != null) && (p.Contacts != null && p.Contacts.Any(c => c.Value.Trim().ToLower().EndsWith("@email.com"))) || (p.Name != null && p.Name.Trim().ToLower().Contains("john")));