System.Attribute.InternalGetCustomAttributes C# (CSharp) Method

InternalGetCustomAttributes() private static method

private static InternalGetCustomAttributes ( PropertyInfo element, Type type, bool inherit ) : Attribute[]
element PropertyInfo
type Type
inherit bool
return Attribute[]
        private static Attribute[] InternalGetCustomAttributes(PropertyInfo element, Type type, bool inherit)
        {
            // walk up the hierarchy chain
            Attribute[] attributes = (Attribute[])element.GetCustomAttributes(type, inherit);

            if (!inherit)
                return attributes;

            // create the hashtable that keeps track of inherited types
            Hashtable types = new Hashtable(11);

            // create an array list to collect all the requested attibutes
            ArrayList attributeList = new ArrayList();
            CopyToArrayList(attributeList, attributes, types);

            PropertyInfo baseProp = GetParentDefinition(element);
            while (baseProp != null)
            {
                attributes = GetCustomAttributes(baseProp, type, false);
                AddAttributesToList(attributeList, attributes, types);
                baseProp = GetParentDefinition(baseProp);
            }
            return (Attribute[])attributeList.ToArray(type);
        }

Same methods

Attribute::InternalGetCustomAttributes ( EventInfo element, Type type, bool inherit ) : Attribute[]

Usage Example

Beispiel #1
0
        public static Attribute[] GetCustomAttributes(MemberInfo element, Type type, bool inherit)
        {
            if (element == (MemberInfo)null)
            {
                throw new ArgumentNullException("element");
            }
            if (type == (Type)null)
            {
                throw new ArgumentNullException("type");
            }
            if (!type.IsSubclassOf(typeof(Attribute)) && type != typeof(Attribute))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
            }
            switch (element.MemberType)
            {
            case MemberTypes.Event:
                return(Attribute.InternalGetCustomAttributes((EventInfo)element, type, inherit));

            case MemberTypes.Property:
                return(Attribute.InternalGetCustomAttributes((PropertyInfo)element, type, inherit));

            default:
                return(element.GetCustomAttributes(type, inherit) as Attribute[]);
            }
        }
All Usage Examples Of System.Attribute::InternalGetCustomAttributes