How to deep copy between objects of different type

2020-01-31 07:39发布

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.

Inheritence between the template ClassV1 and ClassV2 has been discounted as these 2 classes need to evolve independently. I have considered using both reflection (which is slow) and binary serialisation (which is also slow) to perform the mapping of the common properties.

Is there a preferred approach? Are there any other alternatives?

7条回答
我想做一个坏孩纸
2楼-- · 2020-01-31 08:08

If speed is an issue, you should implement clone methods in the methods themselves.

查看更多
登录 后发表回答