internal static void PlaceArgumentsOnStack(ILGenerator il, ParameterInfo[] pars, ASTList args, int offset, int rhoffset, AST missing){ int k = args.count; int n = k+offset; int m = pars.Length-rhoffset; bool varargs = m > 0 && pars[m-1].IsDefined(Typeob.ParamArrayAttribute, false) && !(k == m && Convert.IsArrayType(args[k-1].InferType(null))); Type varargElemType = varargs ? pars[--m].ParameterType.GetElementType() : null; if (n > m) n = m; for (int i = offset; i < n; i++){ Type ptype = pars[i].ParameterType; AST arg = args[i-offset]; if (arg is ConstantWrapper && ((ConstantWrapper)arg).value == System.Reflection.Missing.Value){ Object defVal = pars[i].DefaultValue; ((ConstantWrapper)arg).value = defVal != System.Convert.DBNull ? defVal : null; } if (ptype.IsByRef) arg.TranslateToILReference(il, ptype.GetElementType()); else arg.TranslateToIL(il, ptype); } if (n < m){ for (int i = n; i < m; i++){ Type ptype = pars[i].ParameterType; if (pars[i].DefaultValue == System.Convert.DBNull) //No default value was specified if (ptype.IsByRef) missing.TranslateToILReference(il, ptype.GetElementType()); else missing.TranslateToIL(il, ptype); else if (ptype.IsByRef) (new ConstantWrapper(pars[i].DefaultValue, null)).TranslateToILReference(il, ptype.GetElementType()); else (new ConstantWrapper(pars[i].DefaultValue, null)).TranslateToIL(il, ptype); } } if (varargs){ n -= offset; //The number of arguments in argList that are already on the stack m = k>n ? k-n : 0; //The number of arguments in argList that are to be placed in the vararg array ConstantWrapper.TranslateToILInt(il, m); il.Emit(OpCodes.Newarr, varargElemType); bool doLdelema = varargElemType.IsValueType && !varargElemType.IsPrimitive; for (int i = 0; i < m; i++){ il.Emit(OpCodes.Dup); ConstantWrapper.TranslateToILInt(il, i); if (doLdelema) il.Emit(OpCodes.Ldelema, varargElemType); args[i+n].TranslateToIL(il, varargElemType); Binding.TranslateToStelem(il, varargElemType); } } }