private int GetMethodToken(MethodBase method, Type[] optionalParameterTypes, bool UseMethodDef)
        {
            int           tkParent = 0;
            ModuleBuilder module   = (ModuleBuilder)this.m_methodBuilder.Module;
            MethodInfo    info     = method as MethodInfo;

            if (method.IsGenericMethod)
            {
                int        num2;
                MethodInfo genericMethodDefinition   = info;
                bool       isGenericMethodDefinition = info.IsGenericMethodDefinition;
                if (!isGenericMethodDefinition)
                {
                    genericMethodDefinition = info.GetGenericMethodDefinition();
                }
                if (!this.m_methodBuilder.Module.Equals(genericMethodDefinition.Module) || ((genericMethodDefinition.DeclaringType != null) && genericMethodDefinition.DeclaringType.IsGenericType))
                {
                    tkParent = this.GetMemberRefToken(genericMethodDefinition, null);
                }
                else
                {
                    tkParent = module.GetMethodTokenInternal(genericMethodDefinition).Token;
                }
                if (isGenericMethodDefinition && UseMethodDef)
                {
                    return(tkParent);
                }
                byte[] signature = SignatureHelper.GetMethodSpecSigHelper(module, info.GetGenericArguments()).InternalGetSignature(out num2);
                return(TypeBuilder.DefineMethodSpec(module.GetNativeHandle(), tkParent, signature, num2));
            }
            if (((method.CallingConvention & CallingConventions.VarArgs) == 0) && ((method.DeclaringType == null) || !method.DeclaringType.IsGenericType))
            {
                if (info != null)
                {
                    return(module.GetMethodTokenInternal(info).Token);
                }
                return(module.GetConstructorToken(method as ConstructorInfo).Token);
            }
            return(this.GetMemberRefToken(method, optionalParameterTypes));
        }