private static List <Ref <IHelperDescriptor <HelperOptions> > > GenerateHelpers(ClosureBuilder builder, int count)
        {
            var helpers = new List <Ref <IHelperDescriptor <HelperOptions> > >();

            for (int i = 0; i < count; i++)
            {
                var helper = new Ref <IHelperDescriptor <HelperOptions> >();
                builder.Add(Const(helper));
                helpers.Add(helper);
            }

            return(helpers);
        }
        private static List <PathInfo> GeneratePaths(ClosureBuilder builder, int count)
        {
            var paths = new List <PathInfo>();

            for (int i = 0; i < count; i++)
            {
                var pathInfo = PathInfo.Parse($"{i}");
                builder.Add(Const(pathInfo));
                paths.Add(pathInfo);
            }

            return(paths);
        }
        private static List <object> GenerateOther(ClosureBuilder builder, int count)
        {
            var others = new List <object>();

            for (int i = 0; i < count; i++)
            {
                var other = new object();
                builder.Add(Const(other));
                others.Add(other);
            }

            return(others);
        }
        public Expression <T> Invoke <T>(Expression <T> expression) where T : Delegate
        {
            var constants = new List <ConstantExpression>();
            var closureCollectorVisitor = new ClosureCollectorVisitor(constants);

            expression = (Expression <T>)closureCollectorVisitor.Visit(expression);

            if (constants.Count == 0)
            {
                return(expression);
            }

            var closureBuilder = new ClosureBuilder();

            for (var index = 0; index < constants.Count; index++)
            {
                var value = constants[index];
                closureBuilder.Add(value);
            }

            var closureDefinition = closureBuilder.Build(out var closure);

            var closureVisitor = new ClosureVisitor(closureDefinition);

            expression = (Expression <T>)closureVisitor.Visit(expression);

            var block = Block()
                        .Parameter(closureDefinition.Key)
                        .Line(Expression.Assign(closureDefinition.Key, Arg(closure)));

            if (expression !.Body is BlockExpression blockExpression)
            {
                var variables = blockExpression.Variables;
                for (var index = 0; index < blockExpression.Variables.Count; index++)
                {
                    block.Parameter(variables[index]);
                }

                block.Lines(blockExpression.Expressions);
            }