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

前端 未结 5 955
故里飘歌
故里飘歌 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条回答
  •  死守一世寂寞
    2021-01-18 17:11

    You can do it via Reflection.

    Something like this:

    Type exportSettingType = ctrl.ExportSettings.GetType();
    
    foreach (PropertyInfo property in exportSettingType.GetProperties())
    {
        object value = property.GetValue(ctrl.ExportSettings, null);
        property.SetValue(secondControl.ExportSettings, value, null);
    }
    

提交回复
热议问题