アプリの構成を使用して2つの会社の設定を保存したいのですが、セクションを使用して、異なるキー名を付けるのではなく、一方のデータを他方のデータから分離できるようにしたいと思います。
私はオンラインでチェックしていますが、人々がセクションを使用したり、それらを使用するための時代遅れの簡単な方法を見つけたりすると、少し圧倒されるようです。誰かが私にそれらの初心者ガイドを渡すことができますか?
以下は、私のapp.configがどのようになるかの例です。
<configSections>
<section name="FBI" type="" />
<section name="FSCS" type="" />
</configSections>
<FSCS>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FSCS>
<FBI>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FBI>
アップデート:
答えに基づく高度なソリューション。誰かが知りたいと思った場合に備えて。
App.config:
<configuration>
<configSections>
<sectionGroup name="FileCheckerConfigGroup">
<section name="FBI" type="System.Configuration.NameValueSectionHandler" />
<section name="FSCS" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
</configSections>
<FileCheckerConfigGroup>
<FSCS>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FSCS>
<FBI>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FBI>
</FileCheckerConfigGroup>
</configuration>
コード:
// Get the application configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get the collection of the section groups.
ConfigurationSectionGroupCollection sectionGroups = config.SectionGroups;
foreach (ConfigurationSectionGroup sectionGroup in sectionGroups)
{
if (sectionGroup.Name == "FileCheckerConfigGroup")
{
foreach (ConfigurationSection configurationSection in sectionGroup.Sections)
{
var section = ConfigurationManager.GetSection(configurationSection.SectionInformation.SectionName) as NameValueCollection;
inputDirectory = section["inputDirectory"]; //"C:\\testfiles";
}
}
}