这里调用了默认的构造函数,简化了创建一个新Cloner对象的方法。为了使这段代码能正常工作,还需要在Content类上实现ICloneable接口。
/// <summary>
/// 克隆
/// </summary>
/// <returns></returns>
public object Clone()
{
AwbBasic tObject = new AwbBasic();
PropertyInfo[] pTar = this.GetType().GetProperties();
PropertyInfo[] pSour = this.GetType().GetProperties();
foreach (PropertyInfo s in pSour)
{
foreach (PropertyInfo t in pTar)
{
if (s.Name == t.Name)
{
t.SetValue(tObject, s.GetValue(this, null), null);
}
}
}
return tObject;
}