工作中用到对同一个类型的对象的赋值,需要逐个属性的赋值赋过去,在网上找了很久没发觉合适的,就自己动手写了个,以做备忘用。

 

    

protected void AutoAssign(object from ,object to)
        {
            foreach (var item in from.GetType().GetProperties())
            {
                item.SetValue(to,item.GetValue(from,null),null);
            }
        }

 

相关文章:

  • 2021-07-29
  • 2022-12-23
  • 2021-08-29
  • 2021-11-28
  • 2021-10-02
  • 2022-02-19
  • 2022-12-23
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-08-05
  • 2021-08-16
相关资源
相似解决方案