2

ドキュメントの標準構成を解析する方法がないという問題が発生しました。

例えば:

private string GetConfigKey(string param)
        {
            Configuration dllConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
            AppSettingsSection dllConfigAppSettings = (AppSettingsSection)dllConfig.GetSection("appSettings");
            return dllConfigAppSettings.Settings[param].Value;
        }

その結果、ファイルから次の形式で設定を取得します。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="host" value="mail.ololo.by"/>
  </appSettings>
  <configSections>
      <section name="provideConfig" type="System.Configuration.DictionarySectionHandler"/>
      <section name="provideMailStatus" type="System.Configuration.DictionarySectionHandler" />
  </configSections>
 <provideConfig>
     <add key="post@gate.ololo.by" value="Mail Subject 1"/>
     <add key="guga@gate.ololo.by" value="Mail Subject 2"/>
 </provideConfig>
  <provideMailStatus>
    <add key="status1" value="send"/>
    <add key="status2" value="draft"/>
    <add key="status2" value="other"/>
  </provideMailStatus>
</configuration>

しかし

Hashtable hashtable =
                (Hashtable)ConfigurationManager.GetSection("provideConfig");
 foreach (DictionaryEntry dictionaryEntry in hashtable)
            {
                Console.WriteLine(dictionaryEntry.Key+" "+dictionaryEntry.Value);
            }

残念ながら、configSections には問題があります。私はそれを得ることができないようです。MB、私は間違った方向に進んでいますか?

PS 構成ファイルに名前を付けることができません"app.config"- プロジェクト dll 名のみ

4

2 に答える 2

2

皆さんありがとう、私は問題に対処しました。誰かが興味を持っているかどうかがわかります。

構成セクション デザイナー Codeplex

.NET 構成コード ジェネレーター

よろしく、やうへん。

于 2012-11-02T08:35:42.237 に答える
2

Config file should be named as executable file name and ".config". Even this executable file uses this dll-file. For example: ConSoleApplication.exe uses MyLibrary.dll. Then config file must be named ConSoleApplication.exe.config

If You need some other name for config file read this

于 2012-10-03T23:02:26.767 に答える