.net中app.config的示例
2016-01-14 15:58
225 查看
以后一些技术性的问题,总结在此。
这几天想把一些软件中的配置放到app.config中,这种做法应该是很成熟的,但是在实际使用中还是遇到了一些问题。
总结一下:
1、添加配置文件:添加--新建项--应用程序配置文件。这个时候就能看到app.config文件了。
2、示例:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="serverConfig" type="System.Configuration.NameValueSectionHandler"/>
<sectionGroup name="pss">
<section name="waveLength" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<appSettings>
<add key ="LD" value ="DFB;DFB TOSA;FP"/>
</appSettings>
<serverConfig>
<add key ="serverName" value ="genuine"/>
<add key ="dtName" value ="device"/>
<add key ="newdtName" value ="Lte"/>
</serverConfig>
<pss>
<waveLength>
<add key ="850" value ="0"/>
<add key ="1310" value ="1"/>
</waveLength>
</pss>
</configuration>
其中<configSections>必须放在<appSettings>前面~!
并且在section 中需要增加type="System.Configuration.NameValueSectionHandler"。
3、引入动态库以及命名空间:
添加引用--System.Configuration
Imports System.Configuration
4、代码中获取这里面的值的代码:
Dim s As Specialized.NameValueCollection = ConfigurationManager.GetSection("serverConfig")
Dim e As String = serverConfig("serverName")
Dim s As Specialized.NameValueCollection = ConfigurationManager.GetSection("pss/waveLength")
Dim e As String = serverConfig("850")
Dim f As String = ConfigurationManager.AppSettings("LD")
这样一些基本配置都可以实现了。
这几天想把一些软件中的配置放到app.config中,这种做法应该是很成熟的,但是在实际使用中还是遇到了一些问题。
总结一下:
1、添加配置文件:添加--新建项--应用程序配置文件。这个时候就能看到app.config文件了。
2、示例:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="serverConfig" type="System.Configuration.NameValueSectionHandler"/>
<sectionGroup name="pss">
<section name="waveLength" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<appSettings>
<add key ="LD" value ="DFB;DFB TOSA;FP"/>
</appSettings>
<serverConfig>
<add key ="serverName" value ="genuine"/>
<add key ="dtName" value ="device"/>
<add key ="newdtName" value ="Lte"/>
</serverConfig>
<pss>
<waveLength>
<add key ="850" value ="0"/>
<add key ="1310" value ="1"/>
</waveLength>
</pss>
</configuration>
其中<configSections>必须放在<appSettings>前面~!
并且在section 中需要增加type="System.Configuration.NameValueSectionHandler"。
3、引入动态库以及命名空间:
添加引用--System.Configuration
Imports System.Configuration
4、代码中获取这里面的值的代码:
Dim s As Specialized.NameValueCollection = ConfigurationManager.GetSection("serverConfig")
Dim e As String = serverConfig("serverName")
Dim s As Specialized.NameValueCollection = ConfigurationManager.GetSection("pss/waveLength")
Dim e As String = serverConfig("850")
Dim f As String = ConfigurationManager.AppSettings("LD")
这样一些基本配置都可以实现了。
相关文章推荐
- Swift 编程语言入门教程
- Android L上锁屏界面滑动不解锁
- 微信第三方登录接口
- android在假设绘制自己定义的bitmap,然后返回给ImageView
- Android 监听SMS短信
- iOS时间戳和NSDate之间的相互转换
- Android Hot patch 技术:Dexposed-来自阿里手机淘宝部门的开源项目
- AndroidStudio添加so文件
- Android Studio 加载.so文件
- IOS - Lable基础用法
- cocos2dx3.2升级Android5的坑
- iOS 星星评价视图 3行搞定
- Unity3D ParticleSystem粒子系统(3.5版
- iOS 隐藏导航栏或状态栏
- Swift - 使用NSURL进行数据的提交和获取(POST与GET)
- IOS #define和预编译指令
- iOSPush原理及实现
- WebView 学习
- UIWebView 字体大小、字体颜色、背景色
- 台式机与笔记本电脑BIOS启动热键