Cloning a complex object is not an easy task. Especially if you need to preserve some object properties references within the object graph. Plus, this is exactly the kind of boring codes you don’t want to be writing , anyway. 😉
I’ve created a library called NetClone, that you can use to configure the clone graph for your object. The object cloner instance keep tracks of which object references must be preserved vs recursively cloned and rely on JSON serialization to duplicate objects.
To get started simply open your Package manager console :
Here are some example of how to use the library
Example : Deep clone an entire objects with minimal configuration
Simple clone for class A where member B will be cloned and it’s member C reference will be preserved after clone.
It has support for collections
It uses Newtonsoft JSON Serializer to copy the objects.
Library also has capability to configure clone on non-generic fluent configuration.
Clone a collection member
Set member of a collection to preserve reference
Github : https://github.com/newsoftinc/NetClone or simply install from nuget package