35 lines
1007 B
C#
35 lines
1007 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace WMS.Web.Core.Help
|
|
{
|
|
[Serializable]
|
|
public static class ClassClone
|
|
{
|
|
public static void CopyPropertiesToD<D>(this object s, D d)
|
|
{
|
|
try
|
|
{
|
|
var Types = s.GetType();//获得类型
|
|
var Typed = d.GetType();
|
|
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
|
{
|
|
foreach (PropertyInfo dp in Typed.GetProperties())
|
|
{
|
|
if (dp.Name == sp.Name)//判断属性名是否相同
|
|
{
|
|
dp.SetValue(d, sp.GetValue(s, null), null);//获得s对象属性的值复制给d对象的属性
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
}
|