Assembly: System.Configuration (in system.configuration.dll)
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Property)] public ref class ConfigurationCollectionAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Property) */ public final class ConfigurationCollectionAttribute extends Attribute
You use the ConfigurationCollectionAttribute attribute to decorate a ConfigurationElementCollection element. This instructs the .NET Framework to instantiate the collection and to initialize it using your custom ConfigurationElement values.
The simplest way of creating 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 attributes instructing the .NET Framework how to instantiate the custom configuration element properties. These types include:
The attributes instructing the .NET Framework how to validate the custom configuration element properties. These types include:
The following example shows how to use the ConfigurationCollectionAttribute.
The example contains four classes. The class TestingConfigurationCollectionAttribute creates a custom configuration section containing a collection of elements. The remaining three classes are used to create the custom section. The custom section type UrlsSection contains an Urls property. This property is a custom collection of type UrlsCollection containing custom elements of type UrlConfigElement. Note that the key for this example to work is the Urls property, decorated with the ConfigurationCollectionAttribute.
The following is an excerpt of the configuration file containing the custom section as defined in the previous sample.
<configuration> <configSections> <section name="MyUrls" type="Samples.AspNet.UrlsSection, ConfigurationCollectionAttribute, Version=22.214.171.124, Culture=neutral, PublicKeyToken=null" /> </configSections> <MyUrls> <urls> <clear /> <add name="Microsoft" url="http://www.microsoft.com" port="0" /> </urls> </MyUrls> </configuration>
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.