usingNewtonsoft.Json;publicstaticclassObjectCopier{/// <summary>/// Perform a deep Copy of the object, using Json as a serialisation method. NOTE: Private members are not cloned using this method./// </summary>/// <typeparam name="T">The type of object being copied.</typeparam>/// <param name="source">The object instance to copy.</param>/// <returns>The copied object.</returns>publicstaticTClone<T>(thisTsource){// Don't serialize a null object, simply return the default for that objectif(ReferenceEquals(source,null)){returndefault(T);}// initialize inner objects individually// for example in default constructor some list property initialized with some values,// but in 'source' these items are cleaned -// without ObjectCreationHandling.Replace default constructor values will be added to resultvardeserializeSettings=newJsonSerializerSettings{ObjectCreationHandling=ObjectCreationHandling.Replace};returnJsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source),deserializeSettings);}}