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);
        }