zoukankan
html css js c++ java
VS2005中读写配置文件(方法二)
File = App.config
<?
xml version="1.0" encoding="utf-8"
?>
<
configuration
>
<
configSections
>
<
section
name
="systems"
type
="ConfigConsoleApplication.SystemsSection, ConfigConsoleApplication"
/>
</
configSections
>
<
systems
>
<
system
name
="Production"
server
="PRODSERVER"
database
="Prod"
/>
<
system
name
="Demo"
server
="DEMOSERVER"
database
="Demo"
/>
<
system
name
="Testing"
server
="TESTSERVER"
database
="Test"
/>
<
system
name
="Development"
server
="DEVSERVER"
database
="DEV"
/>
</
systems
>
</
configuration
>
File = Program.cs
using
System;
using
System.Collections.Generic;
using
System.Collections.Specialized;
using
System.Configuration;
//
remember to add reference in project
using
System.Reflection;
using
System.Text;
namespace
ConfigConsoleApplication
...
{
public
sealed
class
SystemsSection : ConfigurationSection
...
{
public
SystemsSection()
...
{
}
[ConfigurationProperty(
""
, IsDefaultCollectionProperty
=
true
)]
public
SystemsCollection Systems
...
{
get
...
{
return
(SystemsCollection)
base
[
""
];
}
}
}
public
sealed
class
SystemsCollection : ConfigurationElementCollection
...
{
protected
override
ConfigurationElement CreateNewElement()
...
{
return
new
SystemElement();
}
protected
override
object
GetElementKey( ConfigurationElement element )
...
{
return
( (SystemElement)element ).Name;
}
protected
override
ConfigurationElementCollectionType CollectionType
...
{
get
...
{
return
ConfigurationElementCollectionType.BasicMap;
}
}
protected
override
string
ElementName
...
{
get
...
{
return
"
system
"
;
}
}
}
public
sealed
class
SystemElement : ConfigurationElement
...
{
[ConfigurationProperty(
"
name
"
, IsCollectionKey
=
true
, RequiredValue
=
true
)]
public
string
Name
...
{
get
...
{
return
(
string
)
base
[
"
name
"
];
}
set
...
{
base
[
"
name
"
]
=
value;
}
}
[ConfigurationProperty(
"
server
"
, RequiredValue
=
true
)]
public
string
Server
...
{
get
...
{
return
(
string
)
base
[
"
server
"
];
}
set
...
{
base
[
"
server
"
]
=
value;
}
}
[ConfigurationProperty(
"
database
"
, RequiredValue
=
true
)]
public
string
Database
...
{
get
...
{
return
(
string
)
base
[
"
database
"
];
}
set
...
{
base
[
"
database
"
]
=
value;
}
}
public
override
string
ToString()
...
{
string
output
=
"
SystemElement :
"
;
output
+=
string
.Format(
"
Name = {0}
"
, Name );
output
+=
string
.Format(
"
Server = {0}
"
, Server );
output
+=
string
.Format(
"
Database = {0}
"
, Database );
return
output;
}
}
public
class
Program
...
{
static
void
Main(
string
[] args )
...
{
SystemsSection sysSection
=
ConfigurationManager.GetSection(
"
systems
"
)
as
SystemsSection;
SystemsCollection oneCollection
=
sysSection.Systems;
foreach
( SystemElement oneElement
in
oneCollection )
...
{
Console.WriteLine( oneElement.ToString() );
}
}
}
}
靓点博客 http://www.cnblogs.com/mlog 或 http://blog.csdn.net/cml2030
查看全文
相关阅读:
Vue 消息无缝滚动
请求不携带cookie问题
vue中添加favicon
自定义表单-校验数据规则
vue 刷新当前页面的方式
读阮一峰《ECMAScript 6 入门》小结
Java进阶知识点3:更优雅地关闭资源
Java进阶知识点2:看不懂的代码
用Java实现异构数据库的高效通用分页查询功能
Java进阶知识点1:白捡的扩展性
原文地址:https://www.cnblogs.com/mlog/p/2456410.html
最新文章
vue实现打印功能的两种方法
win10系统电脑常用基本操作快捷键
彻底删除mysql服务(清理注册表)
阿里云服务器和本地之间复制粘贴不了的解决办法
谈谈你对this对象的理解
web-garden 和 web-farm 有什么不同 ?
call、apply的作用和区别是什么?
移动端上拉加载下拉刷新插件-mescroll.js插件
手机日历插件——LCalendar 日期显示NAN的解决方案
小程序中间图标突出效果
热门文章
小程序swiper快速入门
echarts适配移动端
js 浮点数加减总结
ios和android相册和相机兼容性bug
jquery手风琴
时间格式转换
Vue自定义函数挂到全局方法
【问题】VUE 同一页面路由参数变化,数据不刷新
将vue-cli 2.x的项目升级到3.x
vue-cli 3.x 使用
Copyright © 2011-2022 走看看