當然 - 真的沒有什麼能阻止你創建儘可能多的自定義配置部分!
嘗試這樣:
<?xml version="1.0"?>
<configuration>
<!-- define the config sections (and possibly section groups) you want in your config file -->
<configSections>
<section name="SqlConnection" type="System.Configuration.NameValueSectionHandler"/>
<section name="PacConnection" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<!-- "implement" those config sections as defined above -->
<SqlConnection>
<add key="abc" value="123" />
</SqlConnection>
<PacConnection>
<add key="abc" value="234" />
</PacConnection>
</configuration>
的System.Configuration.NameValueSectionHandler
是使用含有<add key="...." value="....." />
條目(如<appSettings>
)一個配置節的默認類型。
要得到的值,只要使用這樣的事情:
NameValueCollection sqlConnConfig = ConfigurationManager.GetSection("SqlConnection") as NameValueCollection;
string valueForAbc = sqlConnConfig["abc"];
而且你完全可以搭配,如果你」匹配現有區段處理器類型由.NET以及定義自己的自定義配置部分,我自己定義了一些 - 只需使用你需要的任何東西!