C#读取Appconfig中自定义的节点
作者:网络转载 发布时间:[ 2015/5/15 13:29:46 ] 推荐标签:开发语言
这回程序正常运行了,且mySection 也拿到了配置文件

但是在程序中我们怎么获取这些配置数据呢?我创建了一个处理配置文件的MySectionHelper类,大体如下
1 public class MySectionHelper
2 {
3 readonly XmlNode _section;
4 readonly XmlNode _coustomAssembly;
5 public MySectionHelper(XmlNode section)
6 {
7 _section=section;
8 _coustomAssembly= _section.SelectSingleNode("coustomAssembly");
9 }
10
11 public string CommandsAssembly{get{return _coustomAssembly.Attributes["CommandsAssembly"].Value;}}
12 }
试试行不行,我的配置文件
1 <configSections>
2 <section name="mySection" type="ConfigSolution.ConfigSectionHandler,ConfigSolution"></section>
3 </configSections>
4 <mySection>
5 <port CPort="40001" WPort="40002" SPort="50000"></port>
6 <coustomAssembly CommandsAssembly="HX.Components.Command.Collection" CommandMessagesAssembly="HX.Components.CommandMessage.Collection"></coustomAssembly>
7 </mySection>
运行结果:

好了,一切完成。然后到网上去找找看看有没有更多的资料,果然很多
子阳哥写了一篇《.Net 自定义应用程序配置》大家可以去看看。

sales@spasvo.com