internal override int GetMemberRefToken(MethodBase methodInfo, Type[] optionalParameterTypes)
        {
            Type[] parameterTypes;

            if (optionalParameterTypes != null)
            {
                if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
                }
            }

            if (!(methodInfo is RuntimeMethodInfo) && DynamicMethod.AsDynamicMethod(methodInfo) == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "methodInfo");
            }

            ParameterInfo[] paramInfo = methodInfo.GetParametersNoCopy();
            if (paramInfo != null && paramInfo.Length != 0)
            {
                parameterTypes = new Type[paramInfo.Length];
                for (int i = 0; i < paramInfo.Length; i++)
                {
                    parameterTypes[i] = paramInfo[i].ParameterType;
                }
            }
            else
            {
                parameterTypes = null;
            }

            SignatureHelper sig = GetMemberRefSignature(methodInfo.CallingConvention,
                                                        methodInfo.GetReturnType(),
                                                        parameterTypes,
                                                        optionalParameterTypes);

            return(m_scope.GetTokenFor(new VarArgMethod(methodInfo as MethodInfo, sig)));
        }
        //
        //
        // Token resolution calls
        //
        //
        public override void Emit(OpCode opcode, MethodInfo meth)
        {
            if (meth == null)
            {
                throw new ArgumentNullException("meth");
            }

            int           stackchange = 0;
            int           tempVal     = 0;
            DynamicMethod dynMeth     = DynamicMethod.AsDynamicMethod(meth);

            if (dynMeth == null)
            {
                if (!(meth is RuntimeMethodInfo))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth");
                }

                if (meth.DeclaringType != null && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray))
                {
                    tempVal = m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle);
                }
                else
                {
                    tempVal = m_scope.GetTokenFor(meth.MethodHandle);
                }
            }
            else
            {
                // rule out not allowed operations on DynamicMethods
                if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
                }
                tempVal = m_scope.GetTokenFor(dynMeth);
            }

            EnsureCapacity(7);
            InternalEmit(opcode);

            if (opcode.m_push == StackBehaviour.Varpush &&
                meth.ReturnType != typeof(void))
            {
                stackchange++;
            }
            if (opcode.m_pop == StackBehaviour.Varpop)
            {
                stackchange -= meth.GetParametersNoCopy().Length;
            }
            // Pop the "this" parameter if the method is non-static,
            //  and the instruction is not newobj/ldtoken/ldftn.
            if (!meth.IsStatic &&
                !(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn)))
            {
                stackchange--;
            }

            UpdateStackSize(opcode, stackchange);

            m_length = PutInteger4(tempVal, m_length, m_ILStream);
        }