Example #1
0
        public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > a, Expression <Func <T, bool> > b)
        {
            ParameterExpression p = a.Parameters[0];

            SubstExpressionVisitor visitor = new SubstExpressionVisitor();

            visitor.subst[b.Parameters[0]] = p;

            Expression body = Expression.OrElse(a.Body, visitor.Visit(b.Body));

            return(Expression.Lambda <Func <T, bool> >(body, p));
        }
Example #2
0
        public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > a, Expression <Func <T, bool> > b)
        {
            if (a == null)
            {
                return(b);
            }

            ParameterExpression p = a.Parameters[0];

            SubstExpressionVisitor visitor = new SubstExpressionVisitor();

            visitor.subst[b.Parameters[0]] = p;

            Expression body = Expression.AndAlso(a.Body, visitor.Visit(b.Body));

            return(Expression.Lambda <Func <T, bool> >(body, p));
        }