TypeDescriptor.GetAttributes Method (Type)


Returns a collection of attributes for the specified type of component.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public static AttributeCollection GetAttributes(
	Type componentType


Type: System.Type

The Type of the target component.

Return Value

Type: System.ComponentModel.AttributeCollection

An AttributeCollection with the attributes for the type of the component. If the component is null, this method returns an empty collection.

Call this version of this method only when you do not have an instance of the object.

For attributes with AttributeUsageAttribute.AllowMultiple set to true, the attribute collection removes duplicate instances. These are instances in which the Attribute.TypeId property returns equal values.

When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. For example, some attributes have a constructor parameter that acts as a unique key. For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.


The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.

.NET Framework
Available since 1.1
Return to top