How do you do a deep copy of an object in .NET? 

Important Note BinaryFormatter has been deprecated, and will no longer be available in .NET after November 2023. See BinaryFormatter Obsoletion Strategy I’ve seen a few different approaches to this, but I use a generic utility method as such: Notes: Your class MUST be marked as [Serializable] for this to work. Your source file must include the following code: using … Read more

MySQL: Cloning a MySQL database on the same MySql instance

As the manual says in Copying Databases you can pipe the dump directly into the mysql client: If you’re using MyISAM you could copy the files, but I wouldn’t recommend it. It’s a bit dodgy. Integrated from various good other answers Both mysqldump and mysql commands accept options for setting connection details (and much more), like: Also, if the new database is not … Read more

In Java, what is a shallow copy?

A shallow copy just copies the values of the references in the class. A deep copy copies the values. given: In this case the shallow copy has the same reference (==) and the deep copy only has an equivalent reference (.equals()). If a change is made to the value of a shallowly copied reference, then … Read more

Deep cloning objects

Whereas one approach is to implement the ICloneable interface (described here, so I won’t regurgitate), here’s a nice deep clone object copier I found on The Code Project a while ago and incorporated it into our code. As mentioned elsewhere, it requires your objects to be serializable. The idea is that it serializes your object and then deserializes it into … Read more

What is the difference between pull and clone in git?

They’re basically the same, except clone will setup additional remote tracking branches, not just master. Check out the man page: Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the … Read more

What is the most efficient way to deep clone an object in JavaScript?

Native deep cloning It’s called “structured cloning”, works experimentally in Node 11 and later, and hopefully will land in browsers. See this answer for more details. Fast cloning with data loss – JSON.parse/stringify If you do not use Dates, functions, undefined, Infinity, RegExps, Maps, Sets, Blobs, FileLists, ImageDatas, sparse Arrays, Typed Arrays or other complex types within your object, a … Read more

What is the most efficient way to deep clone an object in JavaScript?

Native deep cloning It’s called “structured cloning”, works experimentally in Node 11 and later, and hopefully will land in browsers. See this answer for more details. Fast cloning with data loss – JSON.parse/stringify If you do not use Dates, functions, undefined, Infinity, RegExps, Maps, Sets, Blobs, FileLists, ImageDatas, sparse Arrays, Typed Arrays or other complex types within your object, a … Read more

How do you make a deep copy of an object?

A safe way is to serialize the object, then deserialize. This ensures everything is a brand new reference. Here’s an article about how to do this efficiently. Caveats: It’s possible for classes to override serialization such that new instances are not created, e.g. for singletons. Also this of course doesn’t work if your classes aren’t Serializable.

What is the most efficient way to deep clone an object in JavaScript?

Native deep cloning It’s called “structured cloning”, works experimentally in Node 11 and later, and hopefully will land in browsers. See this answer for more details. Fast cloning with data loss – JSON.parse/stringify If you do not use Dates, functions, undefined, Infinity, RegExps, Maps, Sets, Blobs, FileLists, ImageDatas, sparse Arrays, Typed Arrays or other complex types within your object, a … Read more