public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > left, Expression <Func <T, bool> > right, string strname) { var dateExpr = Expression.Parameter(typeof(T)); var parameterReplacer = new ParameterReplacer(dateExpr); var leftwhere = parameterReplacer.Replace(left.Body); var rightwhere = parameterReplacer.Replace(right.Body); var body = Expression.And(leftwhere, rightwhere); return(Expression.Lambda <Func <T, bool> >(body, dateExpr)); }
/// <summary> /// Or condition join /// </summary> /// <typeparam name="T"></typeparam> /// <param name="exp_left"></param> /// <param name="exp_right"></param> /// <returns></returns> public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > exp_left, Expression <Func <T, bool> > exp_right) { var candidateExpr = Expression.Parameter(typeof(T), "candidate"); var parameterReplacer = new ParameterReplacer(candidateExpr); var left = parameterReplacer.Replace(exp_left.Body); var right = parameterReplacer.Replace(exp_right.Body); var body = Expression.Or(left, right); return(Expression.Lambda <Func <T, bool> >(body, candidateExpr)); }
public static Expression <Func <X, Y> > Compose <X, Y, Z>(this Expression <Func <Z, Y> > outer, Expression <Func <X, Z> > inner) { return(Expression.Lambda <Func <X, Y> >( ParameterReplacer.Replace(outer.Body, outer.Parameters[0], inner.Body), inner.Parameters[0])); }