System.Reflection.PseudoCustomAttribute.GetCustomAttributes C# (CSharp) Method

GetCustomAttributes() static private method

static private GetCustomAttributes ( RuntimeMethodInfo method, Type caType, bool includeSecCa, int &count ) : System.Attribute[]
method RuntimeMethodInfo
caType System.Type
includeSecCa bool
count int
return System.Attribute[]
        internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, Type caType, bool includeSecCa, out int count) 
        {
            ASSERT.PRECONDITION(method != 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(DllImportAttribute))
            {               
                pca = DllImportAttribute.GetCustomAttribute(method);
                if (pca != null) pcas.Add(pca);
            }
            if (all || caType == typeof(PreserveSigAttribute))
            {               
                pca = PreserveSigAttribute.GetCustomAttribute(method);
                if (pca != null) pcas.Add(pca);
            }
            if (includeSecCa && (all || IsSecurityAttribute(caType)))
            {
                object[] securityAttributes;

                GetSecurityAttributes(method.Module.ModuleHandle, method.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(RuntimeMethodInfo method, 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 ( RuntimePropertyInfo property, Type caType, int &count ) : System.Attribute[]
PseudoCustomAttribute::GetCustomAttributes ( RuntimeType type, Type caType, bool includeSecCa, 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