/****************************************************************************** Copyright 2005-2007 R2@DevFx.NET DevFx.NET is free software; you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DevFx.NET is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /*******************************************************************************/ using System.Configuration; using System.Reflection; using System.Xml; using Lskj.DevFx.Data; namespace Lskj.DevFx.Config.DotNetConfig { /// /// 配置节基础处理类,继承自 /// /// 派生类 /// /// 注意与 的区别 /// public abstract class SectionBaseHandler : ConfigurationSection where T : SectionBaseHandler { /// /// 获取当前配置节实例 /// public static T Current { get { return GroupHandler.GetSection(false); } } /// /// 获取一个值,该值指示反序列化过程中是否遇到未知属性 /// /// 无法识别的属性的名称 /// 无法识别的属性的值 /// 如果反序列化过程中遇到未知属性,则为true protected override bool OnDeserializeUnrecognizedAttribute(string name, string value) { return this.OnDeserializeUnrecognizedFlag; } /// /// 获取一个值,该值指示反序列化过程中是否遇到未知元素 /// /// 未知的子元素的名称 /// 用于反序列化的 对象 /// 如果反序列化过程中遇到未知元素,则为 true protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader) { return this.OnDeserializeUnrecognizedFlag; } /// /// 是否遇到未知的属性或元素 /// /// /// 派生类如果要允许未定义的属性,则必须重写本属性 /// protected virtual bool OnDeserializeUnrecognizedFlag { get { return false; } } /// /// 本配置节对应的Xml /// public virtual string OuterXml { get { return this.outerXml; } } private string outerXml; /// /// 读取配置文件中的 XML /// /// 在配置文件中进行读取操作的 /// true,则只序列化集合的键属性;否则为 false protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { FieldInfo field = reader.GetType().GetField("_rawXml", FieldMemberInfo.FieldBindingFlags); this.outerXml = (string)field.GetValue(reader); base.DeserializeElement(reader, serializeCollectionKey); } } }