InternalGetAttributeUsage() private static method

private static InternalGetAttributeUsage ( Type type ) : AttributeUsageAttribute
type Type
return AttributeUsageAttribute
Esempio n. 1
0
        private static bool InternalParamIsDefined(MethodInfo method, ParameterInfo param, Type type, bool inherit)
        {
            if (param.IsDefined(type, false))
            {
                return(true);
            }
            if (method.DeclaringType == null || !inherit)
            {
                return(false);
            }
            int position = param.Position;

            for (method = method.GetParentDefinition(); method != null; method = method.GetParentDefinition())
            {
                param = method.GetParameters()[position];
                object[] customAttributes = param.GetCustomAttributes(type, false);
                for (int index = 0; index < customAttributes.Length; ++index)
                {
                    AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(customAttributes[index].GetType());
                    if (customAttributes[index] is Attribute && attributeUsage.Inherited)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
 private static void CopyToArrayList(List <Attribute> attributeList, Attribute[] attributes, Dictionary <Type, AttributeUsageAttribute> types)
 {
     for (int index = 0; index < attributes.Length; ++index)
     {
         attributeList.Add(attributes[index]);
         Type type = attributes[index].GetType();
         if (!types.ContainsKey(type))
         {
             types[type] = Attribute.InternalGetAttributeUsage(type);
         }
     }
 }
Esempio n. 3
0
 private static void CopyToArrayList(ArrayList attributeList, Attribute[] attributes, Hashtable types)
 {
     for (int index = 0; index < attributes.Length; ++index)
     {
         attributeList.Add((object)attributes[index]);
         Type type = attributes[index].GetType();
         if (!types.Contains((object)type))
         {
             types[(object)type] = (object)Attribute.InternalGetAttributeUsage(type);
         }
     }
 }
Esempio n. 4
0
 private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
 {
     if (element.IsDefined(attributeType, inherit))
     {
         return(true);
     }
     if (inherit && Attribute.InternalGetAttributeUsage(attributeType).Inherited)
     {
         for (PropertyInfo parentDefinition = Attribute.GetParentDefinition(element); parentDefinition != (PropertyInfo)null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
         {
             if (parentDefinition.IsDefined(attributeType, false))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 5
0
 private static void AddAttributesToList(ArrayList attributeList, Attribute[] attributes, Hashtable types)
 {
     for (int index = 0; index < attributes.Length; ++index)
     {
         Type type = attributes[index].GetType();
         AttributeUsageAttribute attributeUsageAttribute = (AttributeUsageAttribute)types[(object)type];
         if (attributeUsageAttribute == null)
         {
             AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(type);
             types[(object)type] = (object)attributeUsage;
             if (attributeUsage.Inherited)
             {
                 attributeList.Add((object)attributes[index]);
             }
         }
         else if (attributeUsageAttribute.Inherited && attributeUsageAttribute.AllowMultiple)
         {
             attributeList.Add((object)attributes[index]);
         }
     }
 }
Esempio n. 6
0
 private static void AddAttributesToList(List <Attribute> attributeList, Attribute[] attributes, Dictionary <Type, AttributeUsageAttribute> types)
 {
     for (int index = 0; index < attributes.Length; ++index)
     {
         Type type = attributes[index].GetType();
         AttributeUsageAttribute attributeUsageAttribute = (AttributeUsageAttribute)null;
         types.TryGetValue(type, out attributeUsageAttribute);
         if (attributeUsageAttribute == null)
         {
             attributeUsageAttribute = Attribute.InternalGetAttributeUsage(type);
             types[type]             = attributeUsageAttribute;
             if (attributeUsageAttribute.Inherited)
             {
                 attributeList.Add(attributes[index]);
             }
         }
         else if (attributeUsageAttribute.Inherited && attributeUsageAttribute.AllowMultiple)
         {
             attributeList.Add(attributes[index]);
         }
     }
 }
Esempio n. 7
0
 private static bool InternalParamIsDefined(ParameterInfo param, Type type, bool inherit)
 {
     if (param.IsDefined(type, false))
     {
         return(true);
     }
     if (param.Member.DeclaringType == (Type)null || !inherit)
     {
         return(false);
     }
     for (ParameterInfo parentDefinition = Attribute.GetParentDefinition(param); parentDefinition != null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
     {
         object[] customAttributes = parentDefinition.GetCustomAttributes(type, false);
         for (int index = 0; index < customAttributes.Length; ++index)
         {
             AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(customAttributes[index].GetType());
             if (customAttributes[index] is Attribute && attributeUsage.Inherited)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 8
0
        private static Attribute[] InternalParamGetCustomAttributes(ParameterInfo param, Type type, bool inherit)
        {
            List <Type> list = new List <Type>();

            if (type == (Type)null)
            {
                type = typeof(Attribute);
            }
            object[] customAttributes1 = param.GetCustomAttributes(type, false);
            for (int index = 0; index < customAttributes1.Length; ++index)
            {
                Type type1 = customAttributes1[index].GetType();
                if (!Attribute.InternalGetAttributeUsage(type1).AllowMultiple)
                {
                    list.Add(type1);
                }
            }
            Attribute[] attributeArray1 = customAttributes1.Length != 0 ? (Attribute[])customAttributes1 : Attribute.CreateAttributeArrayHelper(type, 0);
            if (param.Member.DeclaringType == (Type)null || !inherit)
            {
                return(attributeArray1);
            }
            for (ParameterInfo parentDefinition = Attribute.GetParentDefinition(param); parentDefinition != null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
            {
                object[] customAttributes2 = parentDefinition.GetCustomAttributes(type, false);
                int      elementCount      = 0;
                for (int index = 0; index < customAttributes2.Length; ++index)
                {
                    Type type1 = customAttributes2[index].GetType();
                    AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(type1);
                    if (attributeUsage.Inherited && !list.Contains(type1))
                    {
                        if (!attributeUsage.AllowMultiple)
                        {
                            list.Add(type1);
                        }
                        ++elementCount;
                    }
                    else
                    {
                        customAttributes2[index] = (object)null;
                    }
                }
                Attribute[] attributeArrayHelper = Attribute.CreateAttributeArrayHelper(type, elementCount);
                int         index1 = 0;
                for (int index2 = 0; index2 < customAttributes2.Length; ++index2)
                {
                    if (customAttributes2[index2] != null)
                    {
                        attributeArrayHelper[index1] = (Attribute)customAttributes2[index2];
                        ++index1;
                    }
                }
                Attribute[] attributeArray2 = attributeArray1;
                attributeArray1 = Attribute.CreateAttributeArrayHelper(type, attributeArray2.Length + index1);
                Array.Copy((Array)attributeArray2, (Array)attributeArray1, attributeArray2.Length);
                int length = attributeArray2.Length;
                for (int index2 = 0; index2 < attributeArrayHelper.Length; ++index2)
                {
                    attributeArray1[length + index2] = attributeArrayHelper[index2];
                }
            }
            return(attributeArray1);
        }
Esempio n. 9
0
        private static Attribute[] InternalParamGetCustomAttributes(MethodInfo method, ParameterInfo param, Type type, bool inherit)
        {
            ArrayList arrayList = new ArrayList();

            if (type == null)
            {
                type = typeof(Attribute);
            }
            object[] customAttributes1 = param.GetCustomAttributes(type, false);
            for (int index = 0; index < customAttributes1.Length; ++index)
            {
                Type type1 = customAttributes1[index].GetType();
                if (!Attribute.InternalGetAttributeUsage(type1).AllowMultiple)
                {
                    arrayList.Add((object)type1);
                }
            }
            Attribute[] attributeArray1 = customAttributes1.Length != 0 ? (Attribute[])customAttributes1 : (Attribute[])Array.CreateInstance(type, 0);
            if (method.DeclaringType == null || !inherit)
            {
                return(attributeArray1);
            }
            int position = param.Position;

            for (method = method.GetParentDefinition(); method != null; method = method.GetParentDefinition())
            {
                param = method.GetParameters()[position];
                object[] customAttributes2 = param.GetCustomAttributes(type, false);
                int      length1           = 0;
                for (int index = 0; index < customAttributes2.Length; ++index)
                {
                    Type type1 = customAttributes2[index].GetType();
                    AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(type1);
                    if (attributeUsage.Inherited && !arrayList.Contains((object)type1))
                    {
                        if (!attributeUsage.AllowMultiple)
                        {
                            arrayList.Add((object)type1);
                        }
                        ++length1;
                    }
                    else
                    {
                        customAttributes2[index] = (object)null;
                    }
                }
                Attribute[] attributeArray2 = (Attribute[])Array.CreateInstance(type, length1);
                int         index1          = 0;
                for (int index2 = 0; index2 < customAttributes2.Length; ++index2)
                {
                    if (customAttributes2[index2] != null)
                    {
                        attributeArray2[index1] = (Attribute)customAttributes2[index2];
                        ++index1;
                    }
                }
                Attribute[] attributeArray3 = attributeArray1;
                attributeArray1 = (Attribute[])Array.CreateInstance(type, attributeArray3.Length + index1);
                Array.Copy((Array)attributeArray3, (Array)attributeArray1, attributeArray3.Length);
                int length2 = attributeArray3.Length;
                for (int index2 = 0; index2 < attributeArray2.Length; ++index2)
                {
                    attributeArray1[length2 + index2] = attributeArray2[index2];
                }
            }
            return(attributeArray1);
        }