Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deep Copy a .NET Class Instance Without Serialization

I am using an instance class from a third-party DLL, and I need to do a deep copy on a particular instance. The class is not marked as Serializable, and therefore I can not use this suggested method using BinaryFormatter.

How can I get a deep copy of this object without using serialization?

like image 364
Josh Stodola Avatar asked Jan 28 '10 19:01

Josh Stodola


People also ask

What is difference between shallow copy and deep copy in C#?

While in shallow copy the members of the copied object refer to the same object as the original object, in a deep copy, separate instances of each of the reference type members in the original instance is created in the new or cloned instance.


1 Answers

I've been using Copyable with great success. It uses reflection under the hood. It is open-sourced. Be sure to read Limitations and pitfalls to see if you can use it.

like image 187
Kenny Eliasson Avatar answered Oct 07 '22 13:10

Kenny Eliasson