Beispiel #1
0
        public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > one,
                                                          Expression <Func <T, bool> > another)
        {
            var candidateExpr     = Expression.Parameter(typeof(T), "candidate");
            var parameterReplacer = new ParameterReplacer(candidateExpr);

            var left  = parameterReplacer.Replace(one.Body);
            var right = parameterReplacer.Replace(another.Body);
            var body  = Expression.Or(left, right);

            return(Expression.Lambda <Func <T, bool> >(body, candidateExpr));
        }
Beispiel #2
0
        public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > one,
                                                           Expression <Func <T, bool> > another)
        {
            var candidateExpr     = Expression.Parameter(typeof(T), "candidate");
            var parameterReplacer = new ParameterReplacer(candidateExpr);

            var left  = parameterReplacer.Replace(one.Body);
            var right = parameterReplacer.Replace(another.Body);
            var body  = Expression.And(left, right);

            return(Expression.Lambda <Func <T, bool> >(body, candidateExpr));
            //  var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
            //return Expression.Lambda<Func<T, bool>>(Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
        }