Enumerate and copy properties from one object to another object of same type

前端 未结 5 964
故里飘歌
故里飘歌 2021-01-18 17:06

I use a third party control which exports some data to different formats. The control has a property ExportSettings. But it is read-only.

I\'ve to manua

5条回答
  •  猫巷女王i
    2021-01-18 17:17

      static void CopyProperties(object dest, object src)
      {
       foreach (PropertyDescriptor item in TypeDescriptor.GetProperties(src))
       {
        item.SetValue(dest, item.GetValue(src));
       } 
      }
    

提交回复
热议问题