1

私の構成セクションには、次のものがあります。

<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    <section name="NFeColumns" type="System.Configuration.DictionarySectionHandler" />
    <section name="CTeColumns" type="System.Configuration.DictionarySectionHandler" />
  </configSections>

  <appSettings>
    <add key="csv.separator" value=";" />
    <add key="infNFe.columns" value="NFeColumns"/>
    <add key="infCte.columns" value="CTeColumns"/>
    <add key="infNFe.filename" value=".\Extracted\NFeCollection.csv"/>
    <add key="infCte.filename" value=".\Extracted\CTeCollection.csv"/>
  </appSettings>

  <NFeColumns>
    <add key="infNFe.Id"  value="Id" />
    <add key="ide.cUF"    value="cUF" />
    <add key="dest.CNPJ"  value="CNPJ" />
    <add key="dest.xNome" value="xNome" />
    <add key="det.nItem"  value="nItem" />
    <add key="prod.cProd" value="cProd" />
    <add key="prod.xProd" value="xProd" />
    <add key="IPI.cEnq"   value="cEnq" />
  </NFeColumns>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

</configuration>

IDictionary から値を取得し、構成ファイルと同じ順序で配置したいと考えています。私はこれをやっています:

 string columnsSectionName = ConfigurationManager.AppSettings[colFileName + ".columns"];
            IDictionary columns = (IDictionary)ConfigurationManager.GetSection(columnsSectionName);

しかし、私はそのm geting the <NFeColumns> in a totally different order, and I can理由を理解していません。手伝ってくれませんか?

4

1 に答える 1

1

ConfigurationManager.GetSectionHashTableのインスタンスを返します。ハッシュ テーブル内のアイテムは、挿入された順序では格納されません。手動で注文する必要があります。

于 2014-04-29T23:45:56.030 に答える