Example #1
0
        public PredicateBuilder <T> And(Expression <Func <T, bool> > predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            predicate = _paramReplacer.VisitAndConvert(predicate, null);

            return(And(predicate.Body));
        }
Example #2
0
    public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > left, Expression <Func <T, bool> > right)
    {
        var p1 = left.Parameters.First();
        var p2 = right.Parameters.First();

        if (p1.Name != p2.Name)
        {
            var replacer = new ParameterReplacerVisitor <Func <T, bool> >(p1);
            right = replacer.VisitAndConvert(right);
        }
        var newBody = Expression.AndAlso(left.Body, right.Body);

        return(Expression.Lambda <Func <T, bool> >(newBody, left.Parameters));
    }