System.Attribute.AddAttributesToList C# (CSharp) Method

AddAttributesToList() private static method

private static AddAttributesToList ( ArrayList attributeList, Attribute attributes, Hashtable types ) : void
attributeList ArrayList
attributes Attribute
types Hashtable
return void
        private static void AddAttributesToList(ArrayList attributeList, Attribute[] attributes, Hashtable types) 
        {
            for (int i = 0; i < attributes.Length; i++) 
            {
                Type attrType = attributes[i].GetType();
                AttributeUsageAttribute usage = (AttributeUsageAttribute)types[attrType];

                if (usage == null) 
                {
                    // the type has never been seen before if it's inheritable add it to the list
                    usage = InternalGetAttributeUsage(attrType);
                    types[attrType] = usage;

                    if (usage.Inherited) 
                        attributeList.Add(attributes[i]);
                }
                else if (usage.Inherited && usage.AllowMultiple)
                {
                    // we saw this type already add it only if it is inheritable and it does allow multiple 
                    attributeList.Add(attributes[i]);
                }
            }
        }

Usage Example

Beispiel #1
0
        private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type type, bool inherit)
        {
            Attribute[] attributes = (Attribute[])element.GetCustomAttributes(type, inherit);
            if (!inherit)
            {
                return(attributes);
            }
            Hashtable types         = new Hashtable(11);
            ArrayList attributeList = new ArrayList();

            Attribute.CopyToArrayList(attributeList, attributes, types);
            for (EventInfo parentDefinition = Attribute.GetParentDefinition(element); parentDefinition != null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
            {
                Attribute[] customAttributes = Attribute.GetCustomAttributes((MemberInfo)parentDefinition, type, false);
                Attribute.AddAttributesToList(attributeList, customAttributes, types);
            }
            return((Attribute[])attributeList.ToArray(type));
        }
All Usage Examples Of System.Attribute::AddAttributesToList