C# 如何使用ConfigurationManager.GetSection(columnsSectionName)获取.config文件的内容而不更改节';点菜?
在我的配置部分,我有以下内容:C# 如何使用ConfigurationManager.GetSection(columnsSectionName)获取.config文件的内容而不更改节';点菜?,c#,configurationmanager,idictionary,C#,Configurationmanager,Idictionary,在我的配置部分,我有以下内容: <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> <section name="NFeColumns" type="System.Configuration.DictionarySectionHandler" /> <section
<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>
然而,我以一种完全不同的顺序得到了答案,我不知道为什么。您能帮助我吗?
ConfigurationManager.GetSection
返回的实例。哈希表中的项不会按插入顺序存储。您必须手动订购
string columnsSectionName = ConfigurationManager.AppSettings[colFileName + ".columns"];
IDictionary columns = (IDictionary)ConfigurationManager.GetSection(columnsSectionName);