using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace HXX.Scanner.Common
{
public class EntityClone
{
///
/// 可父类向子类拷贝
///
///
///
///
///
public static Tc DeriveCopy(Tp parent) where Tc : new()
{
try
{
Tc child = new Tc();
var ParentType = typeof(Tp);
var Properties = ParentType.GetProperties();
foreach (var Propertie in Properties)
{
if (Propertie.CanRead && Propertie.CanWrite)
{
Propertie.SetValue(child, Propertie.GetValue(parent, null), null);
}
}
var fields = ParentType.GetFields();
foreach (var f in fields)
{
f.SetValue(child, f.GetValue(parent));
}
return child;
}
catch (Exception)
{
throw;
}
}
}
}