Exemple #1
0
        public Expression AutoInline(InvocationExpression expression)
        {
            this.isLocked = true;
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var lambda       = (LambdaExpression)expression.Expression;
            var childScope   = new ExpressionRewriter(this);
            var lambdaParams = lambda.Parameters;
            var invokeArgs   = expression.Arguments;

            if (lambdaParams.Count != invokeArgs.Count)
            {
                throw new InvalidOperationException("Lambda/invoke mismatch");
            }

            for (var i = 0; i < lambdaParams.Count; i++)
            {
                childScope.Substitute(lambdaParams[i], invokeArgs[i]);
            }

            return(childScope.Apply(lambda.Body));
        }
        public static Expression <Func <T, bool> > And <T>(
            this Expression <Func <T, bool> > expression1, Expression <Func <T, bool> > expression2)
        {
            var newY =
                new ExpressionRewriter().Substitute(expression2.Parameters[0], expression1.Parameters[0]).Inline()
                .Apply(expression2.Body);

            return(Expression.Lambda <Func <T, bool> >(Expression.AndAlso(expression1.Body, newY), expression1.Parameters));
        }
        private ExpressionRewriter(ExpressionRewriter parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            this.subst = new Dictionary<Expression, Expression>(parent.subst);
            this.inline = parent.inline;
        }
Exemple #4
0
        private ExpressionRewriter(ExpressionRewriter parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            this.subst  = new Dictionary <Expression, Expression>(parent.subst);
            this.inline = parent.inline;
        }
        public Expression AutoInline(InvocationExpression expression)
        {
            this.isLocked = true;
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var lambda = (LambdaExpression)expression.Expression;
            var childScope = new ExpressionRewriter(this);
            var lambdaParams = lambda.Parameters;
            var invokeArgs = expression.Arguments;
            if (lambdaParams.Count != invokeArgs.Count)
            {
                throw new InvalidOperationException("Lambda/invoke mismatch");
            }

            for (var i = 0; i < lambdaParams.Count; i++)
            {
                childScope.Substitute(lambdaParams[i], invokeArgs[i]);
            }

            return childScope.Apply(lambda.Body);
        }