Clone with better performance

前端 未结 8 2385
一整个雨季
一整个雨季 2020-12-14 04:29

I want to create deep copy method and I found 3 ways to execute it

1-deep copy with pass each property 1 by 1

2-using reflection

3-using serializatio

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 04:50

    Reflection can be use to produce DynamicMethod which can be more efficient than manually copy (auto-properties can be copied by accessing fields directly breaking scope via skipVisibilityCheck). DynamicMethod offer you a delegate you can keep in static readonly field to clone your object. This is the fast and easy way to do it but not forcely the cleanest. Serialization is slow and not adapted.

提交回复
热议问题