System.Reflection.PseudoCustomAttribute.GetCustomAttributes C# (CSharp) Méthode

GetCustomAttributes() static private méthode

static private GetCustomAttributes ( RuntimeType type, Type caType, bool includeSecCa, int &count ) : System.Attribute[]
type RuntimeType
caType System.Type
includeSecCa bool
count int
Résultat System.Attribute[]
        internal static Attribute[] GetCustomAttributes(RuntimeType type, Type caType, bool includeSecCa, out int count) 
        {
            ASSERT.PRECONDITION(type != null);
            ASSERT.PRECONDITION(caType != null);

            count = 0;

            bool all = caType == typeof(object) || caType == typeof(Attribute);
            if (!all && s_pca[caType]  == null && !IsSecurityAttribute(caType))
                return new Attribute[0];

            List<Attribute> pcas = new List<Attribute>();
            Attribute pca = null;

            if (all || caType == typeof(SerializableAttribute))
            {               
                pca = SerializableAttribute.GetCustomAttribute(type);
                if (pca != null) pcas.Add(pca);
            }
            if (all || caType == typeof(ComImportAttribute))
            {               
                pca = ComImportAttribute.GetCustomAttribute(type);
                if (pca != null) pcas.Add(pca);
            }
            if (includeSecCa && (all || IsSecurityAttribute(caType)))
            {               
                if (!type.IsGenericParameter)
                {
                    if (type.IsGenericType)
                        type = (RuntimeType)type.GetGenericTypeDefinition();
                    
                    object[] securityAttributes;
                    GetSecurityAttributes(type.Module.ModuleHandle, type.MetadataToken, out securityAttributes);
                    if (securityAttributes != null)
                        foreach(object a in securityAttributes)
                            if (caType == a.GetType() || a.GetType().IsSubclassOf(caType))
                                pcas.Add((Attribute)a);
                }
            }

            count = pcas.Count;
            return pcas.ToArray();
        }
        internal static bool IsDefined(RuntimeType type, Type caType) 

Same methods

PseudoCustomAttribute::GetCustomAttributes ( Assembly assembly, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( Module module, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( ParameterInfo parameter, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimeConstructorInfo ctor, Type caType, bool includeSecCa, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimeEventInfo e, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimeFieldInfo field, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimeMethodInfo method, Type caType, bool includeSecCa, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimePropertyInfo property, Type caType, int &count ) : System.Attribute[]

Usage Example

        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);
        }
All Usage Examples Of System.Reflection.PseudoCustomAttribute::GetCustomAttributes