GetCustomAttributesBase() статический приватный Метод

static private GetCustomAttributesBase ( ICustomAttributeProvider obj, Type attributeType ) : object[]
obj ICustomAttributeProvider
attributeType Type
Результат object[]
Пример #1
0
 internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, bool inherit)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (!inherit)
     {
         return((object[])MonoCustomAttrs.GetCustomAttributesBase(obj, null).Clone());
     }
     return(MonoCustomAttrs.GetCustomAttributes(obj, typeof(MonoCustomAttrs), inherit));
 }
Пример #2
0
        internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type attributeType, bool inherit)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (attributeType == null)
            {
                throw new ArgumentNullException("attributeType");
            }
            if (attributeType == typeof(MonoCustomAttrs))
            {
                attributeType = null;
            }
            object[] customAttributesBase = MonoCustomAttrs.GetCustomAttributesBase(obj, attributeType);
            if (!inherit && customAttributesBase.Length == 1)
            {
                object[] array;
                if (attributeType != null)
                {
                    if (attributeType.IsAssignableFrom(customAttributesBase[0].GetType()))
                    {
                        array    = (object[])Array.CreateInstance(attributeType, 1);
                        array[0] = customAttributesBase[0];
                    }
                    else
                    {
                        array = (object[])Array.CreateInstance(attributeType, 0);
                    }
                }
                else
                {
                    array    = (object[])Array.CreateInstance(customAttributesBase[0].GetType(), 1);
                    array[0] = customAttributesBase[0];
                }
                return(array);
            }
            if (attributeType != null && attributeType.IsSealed && inherit)
            {
                AttributeUsageAttribute attributeUsageAttribute = MonoCustomAttrs.RetrieveAttributeUsage(attributeType);
                if (!attributeUsageAttribute.Inherited)
                {
                    inherit = false;
                }
            }
            int       capacity  = (customAttributesBase.Length >= 16) ? 16 : customAttributesBase.Length;
            Hashtable hashtable = new Hashtable(capacity);
            ArrayList arrayList = new ArrayList(capacity);
            ICustomAttributeProvider customAttributeProvider = obj;
            int num = 0;

            do
            {
                foreach (object obj2 in customAttributesBase)
                {
                    Type type = obj2.GetType();
                    if (attributeType == null || attributeType.IsAssignableFrom(type))
                    {
                        MonoCustomAttrs.AttributeInfo attributeInfo = (MonoCustomAttrs.AttributeInfo)hashtable[type];
                        AttributeUsageAttribute       attributeUsageAttribute2;
                        if (attributeInfo != null)
                        {
                            attributeUsageAttribute2 = attributeInfo.Usage;
                        }
                        else
                        {
                            attributeUsageAttribute2 = MonoCustomAttrs.RetrieveAttributeUsage(type);
                        }
                        if ((num == 0 || attributeUsageAttribute2.Inherited) && (attributeUsageAttribute2.AllowMultiple || attributeInfo == null || (attributeInfo != null && attributeInfo.InheritanceLevel == num)))
                        {
                            arrayList.Add(obj2);
                        }
                        if (attributeInfo == null)
                        {
                            hashtable.Add(type, new MonoCustomAttrs.AttributeInfo(attributeUsageAttribute2, num));
                        }
                    }
                }
                if ((customAttributeProvider = MonoCustomAttrs.GetBase(customAttributeProvider)) != null)
                {
                    num++;
                    customAttributesBase = MonoCustomAttrs.GetCustomAttributesBase(customAttributeProvider, attributeType);
                }
            }while (inherit && customAttributeProvider != null);
            object[] array3;
            if (attributeType == null || attributeType.IsValueType)
            {
                array3 = (object[])Array.CreateInstance(typeof(Attribute), arrayList.Count);
            }
            else
            {
                array3 = (Array.CreateInstance(attributeType, arrayList.Count) as object[]);
            }
            arrayList.CopyTo(array3, 0);
            return(array3);
        }