c# – ConfigurationManager.GetSection和Configuration.GetSect
我正在尝试基于AppSettings创建自定义配置文件部分:
<configSections> <section name="customConfiguration" type="System.Configuration.AppSettingsSection,System.Configuration,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/> </configSections> 当我尝试通过ConfigurationManager.GetSection(“customConfiguration”)读取它时,返回的对象是System.Configuration.KeyValueInternalCollection类型.我无法读取此集合的值,虽然我可以看到键,但我无法将其转换为AppSettingsSection. This Stackoverflow回答建议我应该使用 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection customSettingSection = (AppSettingsSection)config.GetSection("customConfiguration"); 这很有效.我的问题是:ConfigurationManager.GetSection()和Configuration.GetSection()之间有什么区别?我何时应该使用另一个?何时应该使用另一个? 解决方法
根据配置类
http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx上的MSDN文档,
具体来说,在客户端应用程序中,ConfigurationManager检索通过合并应用程序配置文件,本地用户配置文件和漫游配置文件获得的配置文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |