• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

.Net配置文件常用配置说明

发布: 2007-7-01 11:09 | 作者: admin | 来源: | 查看: 20次 | 进入软件测试论坛讨论

领测软件测试网 配置文件内容如下:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<section name="mySection" type="System.Configuration.NameValueSectionHandler"/>

<section name="mySingleTagSection" type="System.Configuration.SingleTagSectionHandler"/>

<section name="myDictionarySection" type="System.Configuration.DictionarySectionHandler"/>



<sectionGroup name="mySections">

<section name="mySection1" type="System.Configuration.NameValueSectionHandler"/>

<section name="mySection2" type="System.Configuration.NameValueSectionHandler"/>

</sectionGroup>

</configSections>



<mySection>

<add key="key1" value="value1" />

<add key="key2" value="value2" />

</mySection>



<mySingleTagSection setting1="value1" setting2="value2" setting3="value3" />



<myDictionarySection>

<add key="DictionarySectionKey1" value="DictionarySectionValue1"/>

<add key="DictionarySectionKey2" value="DictionarySectionValue2"/>

<add key="DictionarySectionKey3" value="DictionarySectionValue3"/>

</myDictionarySection>



<mySections>

<mySection1>

<add key="mySection1_key1" value="mySection1_value1" />

<add key="mySection1_key2" value="mySection1_value2" />

</mySection1>

<mySection2>

<add key="mySection2_key1" value="mySection2_value1" />

<add key="mySection2_key2" value="mySection2_value2" />

</mySection2>

</mySections>



<appSettings>

<add key="appkey1" value="appvalue1" />

<add key="appkey2" value="appvalue2" />

</appSettings>

</configuration>



代码片断如下:

private static void TestAppSettings()

{

Console.WriteLine("TestAppSettings ...");



NameValueCollection config = ConfigurationSettings.AppSettings;



Console.WriteLine("value1:" + config["key1"]);

Console.WriteLine("value2:" + config["key2"]);



Console.WriteLine();

}

private static void TestSection()

{

Console.WriteLine("TestSection ...");



NameValueCollection config ;

config = (NameValueCollection)ConfigurationSettings.GetConfig("mySection");

Console.WriteLine("value1:" + config["key1"]);

Console.WriteLine("value2:" + config["key2"]);



Console.WriteLine();

}



private static void TestSingleTagSection()

{

Console.WriteLine("TestSingleTagSection ...");



IDictionary dic ;

dic = (IDictionary)ConfigurationSettings.GetConfig("mySingleTagSection");

Console.WriteLine("value1:" + dic["setting1"]);

Console.WriteLine("value2:" + dic["setting2"]);

Console.WriteLine("value3:" + dic["setting3"]);



Console.WriteLine();

}



private static void TestDictionarySection()

{

Console.WriteLine("TestDictionarySection ...");



IDictionary dic ;

dic = (IDictionary)ConfigurationSettings.GetConfig("myDictionarySection");

Console.WriteLine("DictionarySectionValue1:" + dic["DictionarySectionKey1"]);

Console.WriteLine("DictionarySectionValue2:" + dic["DictionarySectionKey2"]);

Console.WriteLine("DictionarySectionValue3:" + dic["DictionarySectionKey3"]);



Console.WriteLine();

}



private static void TestSectionGroup()

{

Console.WriteLine("TestSectionGroup ...");



NameValueCollection config1 ;

NameValueCollection config2 ;

config1 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection1");

config2 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection2");



Console.WriteLine("mySections/mySections1/value1:" + config1["mySection1_key1"]);

Console.WriteLine("mySections/mySections1/value2:" + config1["mySection1_key2"]);



Console.WriteLine("mySections/mySections2/value1:" + config2["mySection2_key1"]);

Console.WriteLine("mySections/mySections2/value2:" + config2["mySection2_key2"]);



Console.WriteLine();

}





延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网