How to deep copy between objects of different types in C#.NET

前端 未结 7 1264
孤街浪徒
孤街浪徒 2020-12-06 01:55

I have a requirement to map all of the field values and child collections between ObjectV1 and ObjectV2 by field name. ObjectV2 is in a different namspace to ObjectV1.

7条回答
  •  自闭症患者
    2020-12-06 02:48

    You might want to take a look at AutoMapper, a library which specializes in copying values between objects. It uses convention over configuration, so if the properties really have the exaxt same names it will do almost all of the work for you.

提交回复
热议问题