#region 两个类对拷
public static void Mapper<T1, T2>(ref T1 to, T2 from)
{
foreach (var pi in from.GetType().GetProperties())
{
foreach (var objPi in to.GetType().GetProperties())
{
if (pi.Name == objPi.Name && objPi.PropertyType == pi.PropertyType && pi.Name != "Id" && pi.Name != "ID")
{
var value = pi.GetValue(from, null);
objPi.SetValue(to, value, null);
}
}
}
}
#endregion
C# 复制对象
最新推荐文章于 2023-10-29 00:29:53 发布