接着上次在
《朗志轻量级项目管理解决方案》中对Aspect的改进,
注意,这里我们实现了IXmlSerialization接口,以实现自定义的反序列化操作,还应注意的是在反串行的过程中,这里我们使用了一个自已实现的深拷贝DeepCopy
注意,这里我们实现了IXmlSerialization接口,以实现自定义的反序列化操作,还应注意的是在反串行的过程中,这里我们使用了一个自已实现的深拷贝DeepCopy
public
class
AspectCollection:CollectionBase,IXmlSerializable
{
public AspectCollection()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Add(AspectItem ai)
{
this.InnerList.Add(ai);
}
public new AspectItem this[int index]
{
get
{
return this.InnerList[index] as AspectItem;
}
set
{
this.InnerList[index]=value;
}
}
IXmlSerializable 成员#region IXmlSerializable 成员
public void WriteXml(XmlWriter writer)
{
// TODO: 添加 AspectCollection.WriteXml 实现
foreach(AspectItem ai in this.InnerList)
{
writer.WriteStartElement("Aspect");
writer.WriteAttributeString("","type","",ai.Type);
writer.WriteAttributeString("","deploy-model","",ai.DeployModel);
writer.WriteAttributeString("","pointcut-type","",ai.PointCutType);
writer.WriteAttributeString("","action-position","",ai.ActionPosition);
ai.Rules.WriteXml(writer);
writer.WriteEndElement();
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
// TODO: 添加 AspectCollection.GetSchema 实现
return null;
}
public void ReadXml(XmlReader reader)
{
// TODO: 添加 AspectCollection.ReadXml 实现
base.Clear();
reader.MoveToContent();
AspectCollection ac=new AspectCollection();
RuleCollection rc=new RuleCollection();
AspectItem ai=new AspectItem();
while(reader.Read())
{
if (reader.IsStartElement("Aspect"))
{
ai=new AspectItem();
rc.Clear();
reader.MoveToAttribute("type");
ai.Type=reader.Value;
reader.MoveToAttribute("deploy-model");
ai.DeployModel=reader.Value;
reader.MoveToAttribute("pointcut-type");
ai.PointCutType=reader.Value;
reader.MoveToAttribute("action-position");
ai.ActionPosition=reader.Value;
this.Add(ai);
continue;
}
if (reader.IsStartElement("Rule"))
{
RuleItem ri=new RuleItem();
reader.MoveToAttribute("type");
ri.type=reader.Value;
reader.MoveToAttribute("match");
ri.match=reader.Value;
rc.Add(ri);
ai.Rules=rc.DeepCopy();
}
}
}
这里我使用了.net内置的序列化功能
{
public AspectCollection()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Add(AspectItem ai)
{
this.InnerList.Add(ai);
}
public new AspectItem this[int index]
{
get
{
return this.InnerList[index] as AspectItem;
}
set
{
this.InnerList[index]=value;
}
}
IXmlSerializable 成员#region IXmlSerializable 成员
public void WriteXml(XmlWriter writer)
{
// TODO: 添加 AspectCollection.WriteXml 实现
foreach(AspectItem ai in this.InnerList)
{
writer.WriteStartElement("Aspect");
writer.WriteAttributeString("","type","",ai.Type);
writer.WriteAttributeString("","deploy-model","",ai.DeployModel);
writer.WriteAttributeString("","pointcut-type","",ai.PointCutType);
writer.WriteAttributeString("","action-position","",ai.ActionPosition);
ai.Rules.WriteXml(writer);
writer.WriteEndElement();
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
// TODO: 添加 AspectCollection.GetSchema 实现
return null;
}
public void ReadXml(XmlReader reader)
{
// TODO: 添加 AspectCollection.ReadXml 实现
base.Clear();
reader.MoveToContent();
AspectCollection ac=new AspectCollection();
RuleCollection rc=new RuleCollection();
AspectItem ai=new AspectItem();
while(reader.Read())
{
if (reader.IsStartElement("Aspect"))
{
ai=new AspectItem();
rc.Clear();
reader.MoveToAttribute("type");
ai.Type=reader.Value;
reader.MoveToAttribute("deploy-model");
ai.DeployModel=reader.Value;
reader.MoveToAttribute("pointcut-type");
ai.PointCutType=reader.Value;
reader.MoveToAttribute("action-position");
ai.ActionPosition=reader.Value;
this.Add(ai);
continue;
}
if (reader.IsStartElement("Rule"))
{
RuleItem ri=new RuleItem();
reader.MoveToAttribute("type");
ri.type=reader.Value;
reader.MoveToAttribute("match");
ri.match=reader.Value;
rc.Add(ri);
ai.Rules=rc.DeepCopy();
}
}
}
using
System;
using System.Xml.Serialization;
namespace Langzhi.Aspect
{
/**//// <summary>
/// AspectItem 的摘要说明。
/// </summary>
[Serializable()]
public class AspectItem
{
public AspectItem()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private string m_Type;
private string m_DeployModel;
private string m_PointCutType;
private string m_ActionPosition;
private RuleCollection m_RuleCollection;
// private string m_ID;
private string m_AssemblyName;
private string m_ClassName;
[XmlAttribute("type")]
public string Type
{
get
{
return this.m_Type;
}
set
{
this.m_Type=value;
}
}
[XmlAttribute("deploy-model")]
public string DeployModel
{
get
{
return this.m_DeployModel;
}
set
{
this.m_DeployModel=value;
}
}
[XmlAttribute("pointcut-type")]
public string PointCutType
{
get
{
return this.m_PointCutType;
}
set
{
this.m_PointCutType=value;
}
}
[XmlAttribute("action-position")]
public string ActionPosition
{
get
{
return this.m_ActionPosition;
}
set
{
this.m_ActionPosition=value;
}
}
// [XmlAttribute("id")]
// public string ID
// {
// get
// {
// return this.m_ID;
// }
// set
// {
// this.m_ID = value;
// }
//
// }
[NonSerialized()]
public string ID;
[NonSerialized()]
public string AssemblyName;
[NonSerialized()]
public string ClassName;
[NonSerialized()]
public IAspect SingletonAspect;
public RuleCollection Rules
{
get
{
return this.m_RuleCollection;
}
set
using System.Xml.Serialization;
namespace Langzhi.Aspect
{
/**//// <summary>
/// AspectItem 的摘要说明。
/// </summary>
[Serializable()]
public class AspectItem
{
public AspectItem()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private string m_Type;
private string m_DeployModel;
private string m_PointCutType;
private string m_ActionPosition;
private RuleCollection m_RuleCollection;
// private string m_ID;
private string m_AssemblyName;
private string m_ClassName;
[XmlAttribute("type")]
public string Type
{
get
{
return this.m_Type;
}
set
{
this.m_Type=value;
}
}
[XmlAttribute("deploy-model")]
public string DeployModel
{
get
{
return this.m_DeployModel;
}
set
{
this.m_DeployModel=value;
}
}
[XmlAttribute("pointcut-type")]
public string PointCutType
{
get
{
return this.m_PointCutType;
}
set
{
this.m_PointCutType=value;
}
}
[XmlAttribute("action-position")]
public string ActionPosition
{
get
{
return this.m_ActionPosition;
}
set
{
this.m_ActionPosition=value;
}
}
// [XmlAttribute("id")]
// public string ID
// {
// get
// {
// return this.m_ID;
// }
// set
// {
// this.m_ID = value;
// }
//
// }
[NonSerialized()]
public string ID;
[NonSerialized()]
public string AssemblyName;
[NonSerialized()]
public string ClassName;
[NonSerialized()]
public IAspect SingletonAspect;
public RuleCollection Rules
{
get
{
return this.m_RuleCollection;
}
set