internal static Attribute[] GetCustomAttributes(RuntimeType type, Type caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = (caType == typeof(object)) || (caType == typeof(Attribute));

            if ((!flag && (s_pca[caType] == null)) && !IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();
            Attribute        item = null;

            if (flag || (caType == typeof(SerializableAttribute)))
            {
                item = SerializableAttribute.GetCustomAttribute(type);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if (flag || (caType == typeof(ComImportAttribute)))
            {
                item = ComImportAttribute.GetCustomAttribute(type);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if ((includeSecCa && (flag || IsSecurityAttribute(caType))) && !type.IsGenericParameter)
            {
                object[] objArray;
                if (type.IsGenericType)
                {
                    type = (RuntimeType)type.GetGenericTypeDefinition();
                }
                GetSecurityAttributes(type.Module.ModuleHandle, type.MetadataToken, out objArray);
                if (objArray != null)
                {
                    foreach (object obj2 in objArray)
                    {
                        if ((caType == obj2.GetType()) || obj2.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj2);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }
Exemple #2
0
        internal static Attribute[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null && !PseudoCustomAttribute.IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();

            if (flag || caType == (RuntimeType)typeof(SerializableAttribute))
            {
                Attribute customAttribute = SerializableAttribute.GetCustomAttribute(type);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (flag || caType == (RuntimeType)typeof(ComImportAttribute))
            {
                Attribute customAttribute = ComImportAttribute.GetCustomAttribute(type);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && !type.IsGenericParameter && type.GetElementType() == null)
            {
                if (type.IsGenericType)
                {
                    type = (RuntimeType)type.GetGenericTypeDefinition();
                }
                object[] array;
                PseudoCustomAttribute.GetSecurityAttributes(type.Module.ModuleHandle.GetRuntimeModule(), type.MetadataToken, false, out array);
                if (array != null)
                {
                    foreach (object obj in array)
                    {
                        if (caType == obj.GetType() || obj.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }