Substitute() public method

public Substitute ( Expression from, Expression to ) : ExpressionRewriter
from System.Linq.Expressions.Expression
to System.Linq.Expressions.Expression
return ExpressionRewriter
Ejemplo n.º 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));
        }
Ejemplo n.º 2
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);
        }