Пример #1
0
        private static object[] GetPseudoCustomAttributes(Type type)
        {
            int            count      = 0;
            TypeAttributes Attributes = type.Attributes;

            /* IsSerializable returns true for delegates/enums as well */
            if ((Attributes & TypeAttributes.Serializable) != 0)
            {
                count++;
            }
            if ((Attributes & TypeAttributes.Import) != 0)
            {
                count++;
            }

            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object[count];
            count = 0;

            if ((Attributes & TypeAttributes.Serializable) != 0)
            {
                attrs[count++] = new SerializableAttribute();
            }
            if ((Attributes & TypeAttributes.Import) != 0)
            {
                attrs[count++] = new ComImportAttribute();
            }

            return(attrs);
        }
Пример #2
0
        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());
        }
Пример #3
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());
        }
Пример #4
0
        internal static bool IsDefined(RuntimeType type, RuntimeType caType)
        {
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
            int  num;

            return((flag || !(PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null) || PseudoCustomAttribute.IsSecurityAttribute(caType)) && (((flag || caType == (RuntimeType)typeof(SerializableAttribute)) && SerializableAttribute.IsDefined(type)) || ((flag || caType == (RuntimeType)typeof(ComImportAttribute)) && ComImportAttribute.IsDefined(type)) || ((flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out num).Length != 0)));
        }
Пример #5
0
        internal static bool IsDefined(RuntimeType type, Type caType)
        {
            int  num;
            bool flag = (caType == typeof(object)) || (caType == typeof(Attribute));

            if ((!flag && (s_pca[caType] == null)) && !IsSecurityAttribute(caType))
            {
                return(false);
            }
            return(((flag || (caType == typeof(SerializableAttribute))) && SerializableAttribute.IsDefined(type)) || (((flag || (caType == typeof(ComImportAttribute))) && ComImportAttribute.IsDefined(type)) || ((flag || IsSecurityAttribute(caType)) && (GetCustomAttributes(type, caType, true, out num).Length != 0))));
        }