摘要: 最近写了一段自定义的ConfigurationSection继承类,通过该class可以轻松得定义和读取配置文件信息, 注意这里使用的是c# 2.0来实现的,相比1.1必须通过实现IConfigurationSectionHandler接口来自定义配置节点类方便多了 不论是web.config还是app.config,都可以使用ConfigurationManager类加载配置文件中自定义的节点内容。 以下是配置文件的层次结构: 1?xmlversion="1.0"encoding="utf-8"? 2configuration 3configSections 4sectio 阅读全文
posted @ 2011-01-07 14:25 jiangchao 阅读(438) 评论(0) 推荐(0) 编辑
摘要: 1. 创建配置节类 必须创建继承自ConfigurationSection的对象才能进行配置数据读写操作,ConfigurationSection提供了索引器用来获 取和设置配置数据,需要注意的是拥有ConfigurationProperty特性的属性才会被存储,并且名称要保持大小写完全一致,如下面的代码中, 所有的"id"必须保持一样。 class ConfigSectionData : ConfigurationSection { [ConfigurationProperty("id")] public int Id { get { return (int)this["id"]; 阅读全文
posted @ 2011-01-07 11:09 jiangchao 阅读(2301) 评论(0) 推荐(0) 编辑