Пример #1
0
        private static Expression <Func <T, bool> > CombineLambdas <T>(this Expression <Func <T, bool> > left,

                                                                       Expression <Func <T, bool> > right, ExpressionType expressionType)
        {
            //Remove expressions created with Begin<T>()

            if (IsExpressionBodyConstant(left))
            {
                return(right);
            }


            ParameterExpression p = left.Parameters[0];



            SubstituteParameterVisitor visitor = new SubstituteParameterVisitor();

            visitor.Sub[right.Parameters[0]] = p;



            Expression body = Expression.MakeBinary(expressionType, left.Body, visitor.Visit(right.Body));

            return(Expression.Lambda <Func <T, bool> >(body, p));
        }
Пример #2
0
        private static Expression <Func <T, bool> > CombineLambdas <T>(this Expression <Func <T, bool> > left, Expression <Func <T, bool> > right, ExpressionType expressionType)
        {
            var visitor = new SubstituteParameterVisitor
            {
                Sub =
                {
                    [right.Parameters[0]] = left.Parameters[0]
                }
            };

            Expression body = Expression.MakeBinary(expressionType, left.Body, visitor.Visit(right.Body));

            return(Expression.Lambda <Func <T, bool> >(body, left.Parameters[0]));
        }
Пример #3
0
        private static Expression <Func <T, bool> > CombineLambdas <T>(this Expression <Func <T, bool> > left,
                                                                       Expression <Func <T, bool> > right, ExpressionType expressionType)
        {
            // If the existing expression is a constant, it was created with Begin<T>() and it should be removed.
            if (IsExpressionBodyConstant(left))
            {
                return(right);
            }

            var p = left.Parameters[0];

            var visitor = new SubstituteParameterVisitor();

            visitor.SubstitutionMap[right.Parameters[0]] = p;

            var body = Expression.MakeBinary(expressionType, left.Body, visitor.Visit(right.Body));

            return(Expression.Lambda <Func <T, bool> >(body, p));
        }
        private static Expression <Func <T, bool> > CombineLambdas <T>(this Expression <Func <T, bool> > left,
                                                                       Expression <Func <T, bool> > right, ExpressionType expressionType)
        {
            if (left == null || IsExpressionBodyConstant(left))
            {
                return(right);
            }

            if (right == null)
            {
                return(left);
            }

            var p = left.Parameters[0];

            var visitor = new SubstituteParameterVisitor();

            visitor.Sub[right.Parameters[0]] = p;

            Expression body = Expression.MakeBinary(expressionType, left.Body, visitor.Visit(right.Body));

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