public int GetTokenFor(RuntimeMethodHandle method)
        {
            IRuntimeMethodInfo          methodInfo = method.GetMethodInfo();
            RuntimeMethodHandleInternal value      = methodInfo.Value;

            if (methodInfo != null && !RuntimeMethodHandle.IsDynamicMethod(value))
            {
                RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(value);
                if (declaringType != null && RuntimeTypeHandle.HasInstantiation(declaringType))
                {
                    MethodBase methodBase            = RuntimeType.GetMethodBase(methodInfo);
                    Type       genericTypeDefinition = methodBase.DeclaringType.GetGenericTypeDefinition();
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), methodBase, genericTypeDefinition));
                }
            }
            this.m_tokens.Add(method);
            return(this.m_tokens.Count - 1 | 100663296);
        }
Exemple #2
0
        public int GetTokenFor(RuntimeMethodHandle method)
        {
            IRuntimeMethodInfo          methodReal = method.GetMethodInfo();
            RuntimeMethodHandleInternal rmhi       = methodReal.Value;

            if (methodReal != null && !RuntimeMethodHandle.IsDynamicMethod(rmhi))
            {
                RuntimeType type = RuntimeMethodHandle.GetDeclaringType(rmhi);
                if ((type != null) && RuntimeTypeHandle.HasInstantiation(type))
                {
                    // Do we really need to retrieve this much info just to throw an exception?
                    MethodBase m = RuntimeType.GetMethodBase(methodReal);
                    Type       t = m.DeclaringType.GetGenericTypeDefinition();

                    throw new ArgumentException(SR.Format(SR.Argument_MethodDeclaringTypeGenericLcg, m, t));
                }
            }

            m_tokens.Add(method);
            return(m_tokens.Count - 1 | (int)MetadataTokenType.MethodDef);
        }