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
查看全文
相关阅读:
TCP三次握手(建立连接)/四次挥手(关闭连接)
STL
Hadoop- 集群时间同步
Hadoop- MapReduce在实际应用中常见的调优
Hadoop- HDFS的Safemode
Hadoop- 分布式资源管理YARN架构讲解
Hadoop- Hadoop详解
Linux- Linux自带定时调度Crontab使用详解
Spark- Spark Yarn模式下跑yarn-client无法初始化SparkConext,Over usage of virtual memory
Zeppelin- Linux下安装Zeppelin
原文地址:https://www.cnblogs.com/mlog/p/2456410.html
最新文章
2016.4.10-科比退出江湖之个性
Dijkstra 算法初探
海量数据处理之Bloom Filter详解
红黑树
堆排序算法
快速排序算法C语言版
快速排序算法Java版
选择排序
冒泡排序
第8天排序
热门文章
第7天树
第6天数组和广义表
联合体union的详解
C++提供了四个转换运算符
printf("%d",5.01)和printf("%f",5)的输出结果
虚函数、虚指针和虚表
组合类C++
关于C++中的虚拟继承的一些总结
C++中公有继承、保护继承、私有继承的区别
C++中模板类使用友元模板函数
Copyright © 2011-2022 走看看