C# ConfigurationManager:是否始终使用键值对?

C# ConfigurationManager:是否始终使用键值对?,c#,wpf,configurationmanager,C#,Wpf,Configurationmanager,我尝试使用ConfigurationManager来配置我的c#应用程序。 CM总是只做键值对吗? 喜欢 <add key="k1" value="v1"/> 或者我也可以使用类似的项目 <God Name="Shiva" Spouse="Parvati" Legs="2 Arms="6"/> 您可以使用以下自定义配置部分: 将CustomSectio

我尝试使用ConfigurationManager来配置我的c#应用程序。 CM总是只做键值对吗? 喜欢

 <add key="k1" value="v1"/>

或者我也可以使用类似的项目

 <God Name="Shiva" Spouse="Parvati" Legs="2 Arms="6"/>

您可以使用以下自定义配置部分:

CustomSection
替换为
God
,即可设置。当然,您需要编写额外的代码来阅读它们,但这是完全可行的

<?xml version="1.0" encoding="utf-8"?>
 <configuration>  
   <configSections>
     <section name="CustomSection" type="Samples.AspNet. CustomSection, CustomConfigurationSection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
   </configSections>  

   <CustomSection fileName="default.txt" maxUsers="1000" maxIdleTime="00:15:00" /> 

 </configuration>

另一个很好的例子可以在这里找到:

不过要小心。配置应用于应用程序常量。上帝和他们的能力看起来更适合作为数据源(尽管我想这只是一个例子)