C# 配置选择组获取选择值
我在获取配置信息方面遇到了一些问题,如何获取一些值的C# 配置选择组获取选择值,c#,C#,我在获取配置信息方面遇到了一些问题,如何获取一些值的isupdateable值test1或test2,或者如果paramiter将从外部获取test3 我在配置中有这个示例 <configSections> <sectionGroup name ="UpdateSettings"> <section name="test1" type="System.Configuration.NameValueSectionHandler"/> <sectio
isupdateable
值test1或test2,或者如果paramiter将从外部获取test3
我在配置中有这个示例
<configSections>
<sectionGroup name ="UpdateSettings">
<section name="test1" type="System.Configuration.NameValueSectionHandler"/>
<section name="test2" type="System.Configuration.NameValueSectionHandler"/>
<section name="test3" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<UpdateSettings>
<test1>
<add key="isUpdatable" value="0"/> <!-- get from service - 1, get from config - 0,-->
</test1>
<test2>
<add key="isUpdatable" value="1"/>
</test2>
<test3>
<add key="isUpdatable" value="1"/>
</test3>
</UpdateSettings>
您非常接近,您有一个值数组,因此
sectionSettings[0]
将获得第一个值和sectionSettings[1]
第二个值,依此类推
name = "test1";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionGroup UpdateSettings = config.GetSectionGroup("UpdateSettings");
NameValueCollection sectionSettings = ConfigurationManager.GetSection(name) as NameValueCollection;
var value = sectionSettings[0]["isUpdatable"];
我不想连接到索引-我想连接到名称!
name = "test1";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionGroup UpdateSettings = config.GetSectionGroup("UpdateSettings");
NameValueCollection sectionSettings = ConfigurationManager.GetSection(name) as NameValueCollection;
var value = sectionSettings[0]["isUpdatable"];