Beispiel #1
0
 private MethodCandidate MakeMethodCandidate(MethodBase method, List <ParameterWrapper> parameters, ArgBuilder instanceBuilder, List <ArgBuilder> argBuilders, ReturnBuilder returnBuilder)
 {
     return(new MethodCandidate(
                new MethodTarget(this, method, parameters.Count, instanceBuilder, argBuilders, returnBuilder),
                parameters));
 }
Beispiel #2
0
        private MethodCandidate MakeDefaultCandidate(MethodBase method, List <ParameterWrapper> parameters, ArgBuilder instanceBuilder, List <ArgBuilder> argBuilders, List <ArgBuilder> defaultBuilders, ReturnBuilder returnBuilder, int defaultsUsed)
        {
            List <ArgBuilder>       defaultArgBuilders = new List <ArgBuilder>(argBuilders); // argBuilders.GetRange(0, argBuilders.Count - i);
            List <ParameterWrapper> necessaryParams    = parameters.GetRange(0, parameters.Count - defaultsUsed);

            for (int curDefault = 0; curDefault < defaultsUsed; curDefault++)
            {
                int readIndex  = defaultBuilders.Count - defaultsUsed + curDefault;
                int writeIndex = defaultArgBuilders.Count - defaultsUsed + curDefault;

                if (defaultBuilders[readIndex] != null)
                {
                    defaultArgBuilders[writeIndex] = defaultBuilders[readIndex];
                }
                else
                {
                    necessaryParams.Add(parameters[parameters.Count - defaultsUsed + curDefault]);
                }
            }

            // shift any arguments forward that need to be...
            int curArg = CompilerHelpers.IsStatic(method) ? 0 : 1;

            for (int i = 0; i < defaultArgBuilders.Count; i++)
            {
                if (defaultArgBuilders[i] is DefaultArgBuilder ||
                    defaultArgBuilders[i] is ContextArgBuilder ||
                    defaultArgBuilders[i] is KeywordArgBuilder)
                {
                    continue;
                }

                ReferenceArgBuilder rab = defaultArgBuilders[i] as ReferenceArgBuilder;
                if (rab != null)
                {
                    defaultArgBuilders[i] = new ReferenceArgBuilder(curArg++, rab.Type);
                    continue;
                }

                SimpleArgBuilder sab = (SimpleArgBuilder)defaultArgBuilders[i];
                Debug.Assert(sab.GetType() == typeof(SimpleArgBuilder));
                defaultArgBuilders[i] = new SimpleArgBuilder(curArg++, sab.Type, sab.IsParamsArray, sab.IsParamsDict);
            }

            return(MakeMethodCandidate(method, necessaryParams, instanceBuilder, defaultArgBuilders, returnBuilder));
        }