System.ComponentModel.AttributeCollection Class

Represents a collection of attributes.

See Also: AttributeCollection


public class AttributeCollection : ICollection


The AttributeCollection class is read-only; it does not implement methods to add or remove attributes. You must inherit from this class to implement these methods.

Use the AttributeCollection.Count property to find the number of attributes that exist in the collection.

You can also use the methods of this class to query the collection about its contents. Call the AttributeCollection.Contains(Attribute) method to verify that a specified attribute or attribute array exists in the collection. Call the AttributeCollection.Matches(Attribute) method to verify that a specified attribute or array of attributes exists in the collection, and that the values of the specified attributes are the same as the values in the collection.

While most attributes have default values, default values are not required. If an attribute has no default value, null is returned from the indexed property that takes a type. When defining your own attributes, you can declare a default value by either providing a constructor that takes no arguments, or defining a public static field of your attribute type named "Default".


Namespace: System.ComponentModel
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,,

The members of System.ComponentModel.AttributeCollection are listed below.

See Also: Object

Public Constructors

Initializes a new instance of the AttributeCollection class.

Protected Constructors

Initializes a new instance of the AttributeCollection class.

Public Fields

static readonly

Specifies an empty collection that you can use, rather than creating a new one. This field is read-only.

Public Properties


Gets the number of attributes.

default property
default property

Protected Properties


Gets the attribute collection.

Public Methods

Contains(Attribute) : Boolean

Determines whether this collection of attributes has the specified attribute.

Contains(Attribute[]) : Boolean

Determines whether this attribute collection contains all the specified attributes in the attribute array.

CopyTo(Array, Int32)

Copies the collection to an array, starting at the specified index.

FromExisting(AttributeCollection, params Attribute[]) : AttributeCollection

Creates a new AttributeCollection from an existing AttributeCollection.

GetEnumerator() : IEnumerator

Gets an enumerator for this collection.

Matches(Attribute) : Boolean

Determines whether a specified attribute is the same as an attribute in the collection.

Matches(Attribute[]) : Boolean

Determines whether the attributes in the specified array are the same as the attributes in the collection.

Protected Methods

GetDefaultAttribute(Type) : Attribute

Returns the default Attribute of a given Type.

Explicitly Implemented Interface Members


Gets the number of elements contained in the collection.


Returns an IEnumerator for the IDictionary.


Gets a value indicating whether access to the collection is synchronized (thread-safe).


Gets an object that can be used to synchronize access to the collection.