c#

位置:IT落伍者 >> c# >> 浏览文章

在C#中如何读取配置文件[3]


发布日期:2019年06月17日
 
在C#中如何读取配置文件[3]

通过上面的代码我们可以看出不同的type通过GetConfig返回的类型不同具体获得配置内容的方式也不一样 配置节处理程序

返回类型

SingleTagSectionHandler

SystemsCollectionsIDictionary

DictionarySectionHandler

SystemsCollectionsIDictionary

NameValueSectionHandler

SystemsCollectionsSpecializedNameValueCollection

自定义配置节组

配置节组是使用<sectionGroup>元素将类似的配置节分到同一个组中配置节组声明 部分将创建配置节的包含元素在<configSections>元素中声明配置节组并将属于该组的节置于< sectionGroup>元素中下面是一个包含配置节组的配置文件的例子

<?xml version= encoding=utf ?>

<configuration>

<configSections>

<sectionGroup name=TestGroup>

<section name=Test type=SystemConfigurationNameValueSectionHandler/>

</sectionGroup>

</configSections>

<TestGroup>

<Test>

<add key=Hello value=World/>

</Test>

</TestGroup>

</configuration>

下面是访问这个配置节组的代码

NameValueCollection nc=(NameValueCollection)ConfigurationSettingsGetConfig(TestGroup/Test);

MessageBoxShow(ncAllKeys[]ToString()+ +nc[Hello]); //输出Hello World

[] [] []

               

上一篇:挖掘ADO.NET Entity框架的性能

下一篇:Ado.net访问数据库的方法和步骤