C# 如何定义基本自定义配置节?

C# 如何定义基本自定义配置节?,c#,configuration,settings,C#,Configuration,Settings,我有自己的自定义配置部分,但希望创建一个包含简单键/值的新元素。现在我有了一个工作版本,但对于这样一个简单的任务,似乎有很多代码。有改进的做事方式吗 下面是我的配置和自定义配置类的精简版本 web.config <myRootNode> <myNode> <add key="a" value="" /> <add key="b" value="" /> <add key="c" valu

我有自己的自定义配置部分,但希望创建一个包含简单键/值的新元素。现在我有了一个工作版本,但对于这样一个简单的任务,似乎有很多代码。有改进的做事方式吗

下面是我的配置和自定义配置类的精简版本

web.config

<myRootNode>
    <myNode>
        <add key="a" value="" />
        <add key="b" value="" />
        <add key="c" value="" />
        ...
    </myNode>
    ...any other nodes
</myRootNode>

我猜是这样的:

  <configSections>
      <section name="validationXsds"  type="System.Configuration.DictionarySectionHandler, System" />
  </configSections>


  <validationXsds>
    <add key="http://schemas.xmlsoap.org/soap/envelope/" value="http://dev.ei.directv.com/schemas/xmlsoap/envelope.xsd"/>
    <add key="http://schemas.xmlsoap.org/soap/encoding/" value="http://dev.ei.directv.com/schemas/xmlsoap/encoding.xsd"/>
    <add key="http://ei.directv.com/schemas/envelope/v3_0" value="http://dev.ei.directv.com/schemas/envelope/v3.0/Envelope.xsd"/>
  </validationXsds>

IDictionary xsds = (IDictionary)WebConfigurationManager.GetSection("validationXsds"); 

手动执行此操作需要付出太多的努力。您可以让Visual Studio使用外接程序为您创建分区。

需要Visual Stuiod 2008或更高版本。实际上,VS 2010还不受支持:o(试试这篇文章:
  <configSections>
      <section name="validationXsds"  type="System.Configuration.DictionarySectionHandler, System" />
  </configSections>


  <validationXsds>
    <add key="http://schemas.xmlsoap.org/soap/envelope/" value="http://dev.ei.directv.com/schemas/xmlsoap/envelope.xsd"/>
    <add key="http://schemas.xmlsoap.org/soap/encoding/" value="http://dev.ei.directv.com/schemas/xmlsoap/encoding.xsd"/>
    <add key="http://ei.directv.com/schemas/envelope/v3_0" value="http://dev.ei.directv.com/schemas/envelope/v3.0/Envelope.xsd"/>
  </validationXsds>

IDictionary xsds = (IDictionary)WebConfigurationManager.GetSection("validationXsds"); 
 type="System.Configuration.NameValueSectionHandler, System, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"