GetParentDefinition() private method

private GetParentDefinition ( ) : MethodInfo
return MethodInfo
 internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (PseudoCustomAttribute.IsDefined(method, caType))
     {
         return(true);
     }
     if (CustomAttribute.IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
     {
         return(true);
     }
     if (!inherit)
     {
         return(false);
     }
     method = method.GetParentDefinition();
     while (method != null)
     {
         if (CustomAttribute.IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
         {
             return(true);
         }
         method = method.GetParentDefinition();
     }
     return(false);
 }
        static internal bool IsDefined(MemberInfo member, Type caType, bool inherit)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            bool isDefined = CustomAttribute.IsDefined(member, caType);

            if (isDefined)
            {
                return(true);
            }

            if (inherit)
            {
                AttributeUsageAttribute usage = CustomAttribute.GetAttributeUsage(caType);
                if (!usage.Inherited)
                {
                    return(false); // kill the inheritance request, the attribute does not allow for it
                }
                // walk up the inheritance chain and look for the specified type
                switch (member.MemberType)
                {
                case MemberTypes.Method:
                {
                    RuntimeMethodInfo baseMethod = ((MethodInfo)member).GetParentDefinition() as RuntimeMethodInfo;
                    while (baseMethod != null)
                    {
                        isDefined = CustomAttribute.IsDefined(baseMethod, caType);
                        if (isDefined)
                        {
                            return(true);
                        }
                        baseMethod = baseMethod.GetParentDefinition() as RuntimeMethodInfo;
                    }
                    break;
                }

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType:
                {
                    RuntimeType baseType = ((Type)member).BaseType as RuntimeType;
                    while (baseType != null)
                    {
                        isDefined = CustomAttribute.IsDefined((MemberInfo)baseType, caType);
                        if (isDefined)
                        {
                            return(true);
                        }
                        baseType = ((Type)baseType).BaseType as RuntimeType;
                    }
                    break;
                }
                }
            }
            return(false);
        }
        static internal Object[] GetCustomAttributes(MemberInfo member, Type caType, bool inherit)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            CustomAttribute caItem = GetCustomAttributeList(member, caType, null, 0);

            // if we are asked to go up the hierarchy chain we have to do it now and regardless of the
            // attribute usage for the specific attribute because a derived attribute may ovveride the usage...

            // ... however if the attribute is sealed we can rely on the attribute usage
            if (caType != null && caType.IsSealed && inherit)
            {
                AttributeUsageAttribute usage = CustomAttribute.GetAttributeUsage(caType);
                if (!usage.Inherited)
                {
                    inherit = false; // kill the inheritance request, the attribute does not allow for it
                }
            }

            if (inherit)
            {
                // walk up the inheritance chain and keep accumulating attributes
                int level = 1;
                switch (member.MemberType)
                {
                case MemberTypes.Method:
                {
                    RuntimeMethodInfo baseMethod = ((MethodInfo)member).GetParentDefinition() as RuntimeMethodInfo;
                    while (baseMethod != null)
                    {
                        caItem     = GetCustomAttributeList(baseMethod, caType, caItem, level++);
                        baseMethod = baseMethod.GetParentDefinition() as RuntimeMethodInfo;
                    }
                    break;
                }

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType:
                {
                    RuntimeType baseType = ((Type)member).BaseType as RuntimeType;
                    while (baseType != null)
                    {
                        caItem   = GetCustomAttributeList((MemberInfo)baseType, caType, caItem, level++);
                        baseType = ((Type)baseType).BaseType as RuntimeType;
                    }
                    break;
                }
                }
            }
            return(CustomAttribute.CheckConsistencyAndCreateArray(caItem, caType));
        }
        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);
        }
        internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
            }
            int count = 0;

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

            while (count > 0)
            {
                derivedAttributes.Add(sourceArray[--count]);
            }
            while (method != null)
            {
                object[] objArray2 = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes, !AllowCriticalCustomAttributes(method));
                mustBeInheritable = true;
                for (int i = 0; i < objArray2.Length; i++)
                {
                    derivedAttributes.Add(objArray2[i]);
                }
                method = method.GetParentDefinition();
            }
            object[] destinationArray = CreateAttributeArrayHelper(elementType, derivedAttributes.Count);
            Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
            return(destinationArray);
        }
示例#6
0
        internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
            }
            int count = 0;

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

            while (count > 0)
            {
                objectList.Add((object)customAttributes1[--count]);
            }
            for (; (MethodInfo)method != (MethodInfo)null; method = method.GetParentDefinition())
            {
                object[] customAttributes2 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, (IList)objectList, !CustomAttribute.AllowCriticalCustomAttributes((MethodBase)method));
                mustBeInheritable = true;
                for (int index = 0; index < customAttributes2.Length; ++index)
                {
                    objectList.Add(customAttributes2[index]);
                }
            }
            object[] attributeArrayHelper = CustomAttribute.CreateAttributeArrayHelper(elementType, objectList.Count);
            Array.Copy((Array)objectList.ToArray(), 0, (Array)attributeArrayHelper, 0, objectList.Count);
            return(attributeArrayHelper);
        }
示例#7
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;

            int pcaCount = 0;
            Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out pcaCount);

            // if we are asked to go up the hierarchy chain we have to do it now and regardless of the
            // attribute usage for the specific attribute because a derived attribute may override the usage...           
            // ... however if the attribute is sealed we can rely on the attribute usage
            if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(method));
                if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
                return attributes;
            }

            List<object> result = new List<object>();
            bool mustBeInheritable = false;
            bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters);
            Type arrayType = useObjectArray ? typeof(object) : caType;

            while (pcaCount > 0) 
                result.Add(pca[--pcaCount]);
                
            while (method != null)
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method));
                mustBeInheritable = true;
                for (int i = 0; i < attributes.Length; i++)
                    result.Add(attributes[i]);

                method = method.GetParentDefinition();
            }

            object[] typedResult = CreateAttributeArrayHelper(arrayType, result.Count);
            Array.Copy(result.ToArray(), 0, typedResult, 0, result.Count);
            return typedResult;
        }
示例#8
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            if (PseudoCustomAttribute.IsDefined(method, caType))
                return true;

            if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
                return true;

            if (!inherit)
                return false;

            method = method.GetParentDefinition();

            while (method != null)
            {
                if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
                    return true;

                method = method.GetParentDefinition();
            }

            return false;
        }
示例#9
0
 internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (PseudoCustomAttribute.IsDefined(method, caType))
     {
         return true;
     }
     if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType))
     {
         return true;
     }
     if (inherit)
     {
         method = method.GetParentDefinition() as RuntimeMethodInfo;
         while (method != null)
         {
             if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType, inherit))
             {
                 return true;
             }
             method = method.GetParentDefinition() as RuntimeMethodInfo;
         }
     }
     return false;
 }
示例#10
0
 internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
     {
         method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
     }
     int count = 0;
     Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count);
     if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
     {
         object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType);
         if (count > 0)
         {
             Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
         }
         return objArray;
     }
     List<object> derivedAttributes = new List<object>();
     bool mustBeInheritable = false;
     Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;
     while (count > 0)
     {
         derivedAttributes.Add(sourceArray[--count]);
     }
     while (method != null)
     {
         object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes);
         mustBeInheritable = true;
         for (int i = 0; i < objArray2.Length; i++)
         {
             derivedAttributes.Add(objArray2[i]);
         }
         method = method.GetParentDefinition() as RuntimeMethodInfo;
     }
     object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[];
     Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
     return destinationArray;
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && caType != null)
            {
                FrameworkEventSource.Log.QueryAttributeIsDefined(caType.GetFullNameForEtw());
            }
#endif

            if (PseudoCustomAttribute.IsDefined(method, caType))
                return true;

            if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
                return true;

            if (!inherit)
                return false;

            method = method.GetParentDefinition();

            while (method != null)
            {
                if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
                    return true;

                method = method.GetParentDefinition();
            }

            return false;
        }