internal static Attribute[] GetCustomAttributes(RuntimeConstructorInfo ctor, 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 (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType))) { object[] array; PseudoCustomAttribute.GetSecurityAttributes(ctor.Module.ModuleHandle.GetRuntimeModule(), ctor.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()); }
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()); }
internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, 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) == (RuntimeType)null && !PseudoCustomAttribute.IsSecurityAttribute(caType)) { return(new Attribute[0]); } List <Attribute> attributeList = new List <Attribute>(); if (flag || caType == (RuntimeType)typeof(DllImportAttribute)) { Attribute customAttribute = DllImportAttribute.GetCustomAttribute(method); if (customAttribute != null) { attributeList.Add(customAttribute); } } if (flag || caType == (RuntimeType)typeof(PreserveSigAttribute)) { Attribute customAttribute = PreserveSigAttribute.GetCustomAttribute(method); if (customAttribute != null) { attributeList.Add(customAttribute); } } if (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType))) { object[] securityAttributes; PseudoCustomAttribute.GetSecurityAttributes(method.Module.ModuleHandle.GetRuntimeModule(), method.MetadataToken, false, out securityAttributes); if (securityAttributes != null) { foreach (object obj in securityAttributes) { if ((Type)caType == obj.GetType() || obj.GetType().IsSubclassOf((Type)caType)) { attributeList.Add((Attribute)obj); } } } } count = attributeList.Count; return(attributeList.ToArray()); }
public static IList <CustomAttributeData> GetCustomAttributes(MemberInfo target) { if (target == null) { throw new ArgumentNullException("target"); } IList <CustomAttributeData> customAttributes = GetCustomAttributes(target.Module, target.MetadataToken); int count = 0; Attribute[] attributeArray = null; if (target is RuntimeType) { attributeArray = PseudoCustomAttribute.GetCustomAttributes((RuntimeType)target, typeof(object), false, out count); } else if (target is RuntimeMethodInfo) { attributeArray = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object), false, out count); } else if (target is RuntimeFieldInfo) { attributeArray = PseudoCustomAttribute.GetCustomAttributes((RuntimeFieldInfo)target, typeof(object), out count); } if (count == 0) { return(customAttributes); } CustomAttributeData[] array = new CustomAttributeData[customAttributes.Count + count]; customAttributes.CopyTo(array, count); for (int i = 0; i < count; i++) { if (!PseudoCustomAttribute.IsSecurityAttribute(attributeArray[i].GetType())) { array[i] = new CustomAttributeData(attributeArray[i]); } } return(Array.AsReadOnly <CustomAttributeData>(array)); }
internal static bool IsDefined(RuntimeConstructorInfo ctor, RuntimeType caType) { bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); int num; return((flag || !(PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null)) && ((flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && PseudoCustomAttribute.GetCustomAttributes(ctor, caType, true, out num).Length != 0)); }
internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType) { bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); int num; return((flag || !(PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null)) && (((flag || caType == (RuntimeType)typeof(DllImportAttribute)) && DllImportAttribute.IsDefined(method)) || ((flag || caType == (RuntimeType)typeof(PreserveSigAttribute)) && PreserveSigAttribute.IsDefined(method)) || ((flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out num).Length != 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))); }