using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; namespace WWPipeLine.Commons { public static class ExpressionExtensions { public static Expression> Or(this Expression> expr1, Expression> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); return Expression.Lambda>(Expression.Or(expr1.Body, invokedExpr), expr1.Parameters); } public static Expression> And(this Expression> expr1, Expression> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); return Expression.Lambda>(Expression.And(expr1.Body, invokedExpr), expr1.Parameters); } public static Expression> WhereAnd(this IEnumerable>> exprs) { Expression> FinalQuery = t => true; foreach (var expr in exprs) { FinalQuery = FinalQuery.And(expr); } return FinalQuery; } public static Expression> WhereOr(this IEnumerable>> exprs) { Expression> FinalQuery = t => false; foreach (var expr in exprs) { FinalQuery = FinalQuery.Or(expr); } return FinalQuery; } } }