Поделиться через


Custom Element for NameValueSectionHandler and DictionarySectionHandler

Defines settings for custom configuration sections that use the NameValueSectionHandler or DictionarySectionHandler classes.

<configuration>
**   <sectionName>**

<sectionName> 
</sectionName>

Child Elements

Element Description
<add> element for NameValueSectionHandler and DictionarySectionHandler Adds custom settings.
<remove> element for NameValueSectionHandler and DictionarySectionHandler Removes a previously defined setting.
<clear>element for NameValueSectionHandler and DictionarySectionHandler Clears all previously defined settings in a section.

Remarks

The <sectionName> element is a custom element defined by a <section> tag in the <configSections> element.

The following table shows the type of object the ConfigurationSettings.GetConfig method returns for each configuration section handler.

Configuration section handler Return type
DictionarySectionHandler Systems.Collections.IDictionary
NameValueSectionHandler Systems.Collections.Specialized.NameValueCollection

Example

The following example shows how to declare sections that use the DictionarySectionHandler and NameValueSectionHandler classes. The custom elements are <dictionarySample>, which contains settings read by the DictionarySectionHandler class, and <mySection>, which contains settings read by the NameValueSectionHandler class.

<configuration>
   <configSections>
      <section name="dictionarySample"
         type="System.Configuration.DictionarySectionHandler,System"/>
      <sectionGroup name="mySectionGroup">
         <section name="mySection"
            type="System.Configuration.NameValueSectionHandler,System" />
      </sectionGroup>
   </configSections>
   <dictionarySample>
      <add key="myKey" value="myValue"/>
   </dictionarySample>
   <mySectionGroup>
      <mySection>
         <add key="key1" value="value1" />
      </mySection>
   </mySectionGroup>
</configuration>

Configuration File

This element can be used in the application configuration file, machine configuration file (Machine.config), and Web.config files that are not at the application directory level.

See Also

Configuration Sections Schema | Configuration Section Settings