Пример #1
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            var parameters = Ctor.GetParameters();

            for (var i = 0; i < parameters.Length; i++)
            {
                if (Parameters[i] == null)
                {
                    var parameter = parameters[i];
                    Parameters[i] = chain.FindVariable(parameter.ParameterType);
                }
            }

            foreach (var parameter in Parameters)
            {
                yield return(parameter);
            }

            foreach (var setter in Setters)
            {
                setter.FindVariable(chain);
            }

            foreach (var setter in Setters)
            {
                yield return(setter.Variable);
            }


            if (ActivatorFrames.Any())
            {
                var standin = new StandinMethodVariables(Variable, chain);

                foreach (var frame in ActivatorFrames)
                {
                    foreach (var variable in frame.FindVariables(standin))
                    {
                        yield return(variable);
                    }
                }
            }
        }
Пример #2
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            switch (Mode)
            {
            case ConstructorCallMode.Variable:
                writer.Write(Declaration() + ";");
                ActivatorFrames.Write(method, writer);

                Next?.GenerateCode(method, writer);
                break;

            case ConstructorCallMode.ReturnValue:
                if (ActivatorFrames.Any())
                {
                    writer.Write(Declaration() + ";");
                    ActivatorFrames.Write(method, writer);

                    writer.Write($"return {Variable.Usage};");
                    Next?.GenerateCode(method, writer);
                }
                else
                {
                    writer.Write($"return {Invocation()};");
                    Next?.GenerateCode(method, writer);
                }


                break;

            case ConstructorCallMode.UsingNestedVariable:
                writer.UsingBlock(Declaration(), w =>
                {
                    ActivatorFrames.Write(method, writer);
                    Next?.GenerateCode(method, w);
                });
                break;
            }
        }