工作中用到对同一个类型的对象的赋值,需要逐个属性的赋值赋过去,在网上找了很久没发觉合适的,就自己动手写了个,以做备忘用。
protected
void AutoAssign(
object
from ,
object to)
{
foreach ( var item in from.GetType().GetProperties())
{
item.SetValue(to,item.GetValue( from, null), null);
}
}
{
foreach ( var item in from.GetType().GetProperties())
{
item.SetValue(to,item.GetValue( from, null), null);
}
}