System.Attribute.InternalGetCustomAttributes C# (CSharp) Method

InternalGetCustomAttributes() private static method

private static InternalGetCustomAttributes ( EventInfo element, Type type, bool inherit ) : Attribute[]
element EventInfo
type Type
inherit bool
return Attribute[]
        private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type type, bool inherit)
        {
            // walk up the hierarchy chain
            Attribute[] attributes = (Attribute[])element.GetCustomAttributes(type, inherit);
            if (inherit)
            {
                // 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);

                EventInfo baseEvent = GetParentDefinition(element);
                while (baseEvent != null)
                {
                    attributes = GetCustomAttributes(baseEvent, type, false);
                    AddAttributesToList(attributeList, attributes, types);
                    baseEvent = GetParentDefinition(baseEvent);
                }
                return (Attribute[])attributeList.ToArray(type);
            }
            else
                return attributes;
        }
        private static EventInfo GetParentDefinition(EventInfo ev)

Same methods

Attribute::InternalGetCustomAttributes ( PropertyInfo 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