This documentation is archived and is not being maintained.

ConfigurationCollectionAttribute Class

Declaratively instructs the .NET Framework to create an instance of a configuration element collection. This class cannot be inherited.

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

public final class ConfigurationCollectionAttribute extends Attribute

You use the ConfigurationCollectionAttribute attribute to decorate a ConfigurationElementCollection element. This instructs the .NET Framework to create an instance of the collection and to initialize it using your custom ConfigurationElement values.


The simplest way to create a custom configuration element is to use the attributed (declarative) model. You declare the elements and decorate them with the ConfigurationCollectionAttribute attribute. For each element marked with this attribute, the .NET Framework uses reflection to read the decorating parameters and create a related ConfigurationElementCollection instance. You can also use the programmatic model. In this case it is your responsibility to declare the custom public collection but also to override the ConfigurationElementCollection member and return the properties collection.

The .NET Framework configuration system provides attribute types that you can use during the creation of custom configuration elements. There are two kinds of attributes:

The following example shows how to use the ConfigurationCollectionAttribute.

This example consists of three classes: UrlsSection, UrlsCollection and UrlConfigElement.The UrlsSection class uses the ConfigurationCollectionAttribute to define a custom configuration section. This section contains a URL collection (defined by the UrlsCollection class) of URL elements (defined by the UrlConfigElement class). When you run the example, an instance of the UrlsSection class is created and the following configuration elements are generated in the application configuration file:

        <section name="MyUrls" type="UrlsSection, 
          ConfigurationCollectionAttribute, Version=, Culture=neutral, PublicKeyToken=null" />
            <remove name="Contoso" />
            <add name="Contoso" url="" port="0" />
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0