using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Configuration; using System.Data.SqlClient; namespace Bowin.Common.Linq { public static class ExpressionBuilder { public static Expression> And(this Expression> first, Expression> second) { return first.Compose>(second, new Func(Expression.And)); } public static Expression Compose(this Expression first, Expression second, Func merge) { Expression expression = ParameterRebinder.ReplaceParameters( first.Parameters.Zip( second.Parameters, (f, s) => new { First = f, Second = s }).ToDictionary(p => p.Second, p => p.First), second.Body); return Expression.Lambda(merge(first.Body, expression), first.Parameters); } public static Expression> Or(this Expression> first, Expression> second) { return first.Compose>(second, new Func(Expression.Or)); } } }