Create a Deep Copy in C#

后端 未结 8 2116
孤独总比滥情好
孤独总比滥情好 2020-12-04 01:48

I want to make a deep copy of an object so I could change the the new copy and still have the option to cancel my changes and get back the original object.

My proble

8条回答
  •  不思量自难忘°
    2020-12-04 02:12

    Agree with SLaks. You allways need custom copying semantics just to distingush between weather you want to have a deep copy or a flat copy. (What is a reference, what a contained reference in a sens of composite reference.)

    The pattern you are talking about is the memento pattern.

    Read the article on how to implement it. But basically it turns out to create a custom copy facitlity. Either internal in the class or external in a "copy factory".

提交回复
热议问题