System.Reflection.RuntimeMethodInfo.GetGenericMethodDefinition C# (CSharp) Method

GetGenericMethodDefinition() public method

public GetGenericMethodDefinition ( ) : MethodInfo
return MethodInfo
        public override MethodInfo GetGenericMethodDefinition() 
        {
            if (!IsGenericMethod)
                throw new InvalidOperationException();
            
            return RuntimeType.GetMethodBase(m_declaringType.GetTypeHandleInternal(), m_handle.StripMethodInstantiation()) as MethodInfo;
        }

Usage Example

        internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = (method.GetGenericMethodDefinition() as RuntimeMethodInfo);
            }
            int i = 0;

            Attribute[] customAttributes = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out i);
            if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
            {
                object[] customAttributes2 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, i, caType, !CustomAttribute.AllowCriticalCustomAttributes(method));
                if (i > 0)
                {
                    Array.Copy(customAttributes, 0, customAttributes2, customAttributes2.Length - i, i);
                }
                return(customAttributes2);
            }
            List <object> list = new List <object>();
            bool          mustBeInheritable = false;
            Type          elementType       = (caType == null || caType.IsValueType || caType.ContainsGenericParameters) ? typeof(object) : caType;

            while (i > 0)
            {
                list.Add(customAttributes[--i]);
            }
            while (method != null)
            {
                object[] customAttributes3 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, list, !CustomAttribute.AllowCriticalCustomAttributes(method));
                mustBeInheritable = true;
                for (int j = 0; j < customAttributes3.Length; j++)
                {
                    list.Add(customAttributes3[j]);
                }
                method = method.GetParentDefinition();
            }
            object[] array = CustomAttribute.CreateAttributeArrayHelper(elementType, list.Count);
            Array.Copy(list.ToArray(), 0, array, 0, list.Count);
            return(array);
        }
All Usage Examples Of System.Reflection.RuntimeMethodInfo::GetGenericMethodDefinition