public static object CloneObject(object o)
{
Type t = o.GetType();
PropertyInfo[] properties = t.GetProperties();
Object p = t.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, o, null);
foreach (PropertyInfo pi in properties)
{
if (pi.CanWrite)
{
object value = pi.GetValue(o, null);
pi.SetValue(p, value, null);
}
}
return p;
}
public static void CloneObject(Employee a,ref Employee_Log b)
{
try
{
var Types = a.GetType();//获得类型
var Typed = typeof(Takeda_Employee_Log);
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
{
foreach (PropertyInfo dp in Typed.GetProperties())
C#复制对象
最新推荐文章于 2025-02-23 17:32:00 发布