GetCustomAttributes() static private method

static private GetCustomAttributes ( Assembly assembly, Type caType, int &count ) : System.Attribute[]
assembly Assembly
caType System.Type
count int
return System.Attribute[]
        internal static object[] GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray      = PseudoCustomAttribute.GetCustomAttributes(parameter, caType, out count);
            object[]    destinationArray = GetCustomAttributes(parameter.GetRuntimeModule(), parameter.MetadataToken, count, caType, !AllowCriticalCustomAttributes(parameter));
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
Esempio n. 2
0
        internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray      = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
            object[]    destinationArray = GetCustomAttributes(property.Module, property.MetadataToken, count, caType);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
Esempio n. 3
0
        internal static object[] GetCustomAttributes(RuntimeConstructorInfo ctor, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray      = PseudoCustomAttribute.GetCustomAttributes(ctor, caType, true, out count);
            object[]    destinationArray = GetCustomAttributes(ctor.Module, ctor.MetadataToken, count, caType);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
Esempio n. 4
0
        internal static object[] GetCustomAttributes(Assembly assembly, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray      = PseudoCustomAttribute.GetCustomAttributes(assembly, caType, out count);
            object[]    destinationArray = GetCustomAttributes(assembly.ManifestModule, assembly.AssemblyHandle.GetToken(), count, caType);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
        internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
            bool        isDecoratedTargetSecurityTransparent = property.GetRuntimeModule().GetRuntimeAssembly().IsAllSecurityTransparent();

            object[] destinationArray = GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, count, caType, isDecoratedTargetSecurityTransparent);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
 internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
 {
     if (type.GetElementType() != null)
     {
         if (!caType.IsValueType)
         {
             return(CustomAttribute.CreateAttributeArrayHelper(caType, 0));
         }
         return(EmptyArray <object> .Value);
     }
     else
     {
         if (type.IsGenericType && !type.IsGenericTypeDefinition)
         {
             type = (type.GetGenericTypeDefinition() as RuntimeType);
         }
         int         i = 0;
         Attribute[] customAttributes = PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out i);
         if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
         {
             object[] customAttributes2 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, i, caType, !CustomAttribute.AllowCriticalCustomAttributes(type));
             if (i > 0)
             {
                 Array.Copy(customAttributes, 0, customAttributes2, customAttributes2.Length - i, i);
             }
             return(customAttributes2);
         }
         List <object> list = new List <object>();
         bool          mustBeInheritable = false;
         Type          elementType       = (caType == null || caType.IsValueType || caType.ContainsGenericParameters) ? typeof(object) : caType;
         while (i > 0)
         {
             list.Add(customAttributes[--i]);
         }
         while (type != (RuntimeType)typeof(object) && type != null)
         {
             object[] customAttributes3 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, 0, caType, mustBeInheritable, list, !CustomAttribute.AllowCriticalCustomAttributes(type));
             mustBeInheritable = true;
             for (int j = 0; j < customAttributes3.Length; j++)
             {
                 list.Add(customAttributes3[j]);
             }
             type = (type.BaseType as RuntimeType);
         }
         object[] array = CustomAttribute.CreateAttributeArrayHelper(elementType, list.Count);
         Array.Copy(list.ToArray(), 0, array, 0, list.Count);
         return(array);
     }
 }
        internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
        {
            if (type.GetElementType() != null)
            {
                if (!caType.IsValueType)
                {
                    return(CreateAttributeArrayHelper(caType, 0));
                }
                return(new object[0]);
            }
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                type = type.GetGenericTypeDefinition() as RuntimeType;
            }
            int count = 0;

            Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out count);
            if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
            {
                object[] objArray = GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, count, caType, !AllowCriticalCustomAttributes(type));
                if (count > 0)
                {
                    Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
                }
                return(objArray);
            }
            List <object> derivedAttributes = new List <object>();
            bool          mustBeInheritable = false;
            Type          elementType       = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;

            while (count > 0)
            {
                derivedAttributes.Add(sourceArray[--count]);
            }
            while ((type != ((RuntimeType)typeof(object))) && (type != null))
            {
                object[] objArray2 = GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes, !AllowCriticalCustomAttributes(type));
                mustBeInheritable = true;
                for (int i = 0; i < objArray2.Length; i++)
                {
                    derivedAttributes.Add(objArray2[i]);
                }
                type = type.BaseType as RuntimeType;
            }
            object[] destinationArray = CreateAttributeArrayHelper(elementType, derivedAttributes.Count);
            Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
            return(destinationArray);
        }
Esempio n. 8
0
        internal static IList <CustomAttributeData> GetCustomAttributesInternal(RuntimeType target)
        {
            IList <CustomAttributeData> customAttributes = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);
            int count = 0;

            Attribute[] attributeArray = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, true, 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++)
            {
                array[i] = new CustomAttributeData(attributeArray[i]);
            }
            return(Array.AsReadOnly <CustomAttributeData>(array));
        }
Esempio n. 9
0
        internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
            }
            int count = 0;

            Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count);
            if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
            {
                object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType);
                if (count > 0)
                {
                    Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
                }
                return(objArray);
            }
            List <object> derivedAttributes = new List <object>();
            bool          mustBeInheritable = false;
            Type          elementType       = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;

            while (count > 0)
            {
                derivedAttributes.Add(sourceArray[--count]);
            }
            while (method != null)
            {
                object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes);
                mustBeInheritable = true;
                for (int i = 0; i < objArray2.Length; i++)
                {
                    derivedAttributes.Add(objArray2[i]);
                }
                method = method.GetParentDefinition() as RuntimeMethodInfo;
            }
            object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[];
            Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
            return(destinationArray);
        }
Esempio n. 10
0
        public static IList <CustomAttributeData> GetCustomAttributes(ParameterInfo target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            IList <CustomAttributeData> customAttributes = GetCustomAttributes(target.Member.Module, target.MetadataToken);
            int count = 0;

            Attribute[] attributeArray = PseudoCustomAttribute.GetCustomAttributes(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++)
            {
                array[i] = new CustomAttributeData(attributeArray[i]);
            }
            return(Array.AsReadOnly <CustomAttributeData>(array));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        internal static bool IsDefined(RuntimeAssembly assembly, RuntimeType caType)
        {
            int num;

            return(PseudoCustomAttribute.GetCustomAttributes(assembly, caType, true, out num).Length != 0);
        }
Esempio n. 14
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)));
        }
Esempio n. 15
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)));
        }