This documentation is archived and is not being maintained.

ConfigurationCollectionAttribute Class

Note: This class is new in the .NET Framework version 2.0.

Declaratively instructs the .NET Framework to instantiate a configuration element collection. This class cannot be inherited.

Namespace: System.Configuration
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
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.

NoteNote

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 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.

No code example is currently available or this language may not be supported.

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=1.0.0.0, 
      Culture=neutral, PublicKeyToken=null" />
  </configSections>
  <MyUrls>
    <urls>
      <clear />
      <add name="Microsoft" url="http://www.microsoft.com" port="0" />
    </urls>
  </MyUrls>
</configuration>

System.Object
   System.Attribute
    System.Configuration.ConfigurationCollectionAttribute

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 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.

.NET Framework

Supported in: 2.0
Show: