Declaratively instructs the .NET Framework to instantiate a configuration property. This class cannot be inherited.
Assembly: System.Configuration (in System.Configuration.dll)
You use the to decorate a configuration property, which will instruct the .NET Framework to instantiate and to initialize the property using the value of the decorating parameter.
The simplest way to create a custom configuration element is to use the attributed (declarative) model. You declare the custom public properties and decorate them with the attribute. For each property marked with this attribute, the .NET Framework uses reflection to read the decorating parameters and create a related ConfigurationProperty instance. You can also use the programmatic model, in which case it is your responsibility to declare the custom public properties and return their 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 attribute types:
The types instructing the .NET Framework how to instantiate the custom configuration-element properties. These types include:
The types instructing the .NET Framework how to validate the custom configuration-element properties. These types include:
The following example shows how to define the properties of a custom ConfigurationSection object using the attribute.
The example contains two classes. The UrlsSection custom class uses the to define its own properties. The UsingConfigurationPropertyAttribute class uses the UrlsSection to read and write the custom section in the application configuration file.
The following is an excerpt of the configuration file containing the custom section as defined in the previous sample.
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="CustomSection" type="UrlsSection, UsingConfigurationPropertyAttribute, Version=22.214.171.124, Culture=neutral, PublicKeyToken=null" /> </configSections> <CustomSection name="Contoso" url="http://www.contoso.com" /> </configuration>
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