Creates deep clone for a class if all members of this class are marked as serializable (uses Json serialization). The input instance of an object. The instance type of an object. Returns new object of provided class.
(this T instance)
| 24 | /// <typeparam name="T">The instance type of an object.</typeparam> |
| 25 | /// <returns>Returns new object of provided class.</returns> |
| 26 | public static T DeepClone<T>(this T instance) |
| 27 | where T : new() |
| 28 | { |
| 29 | var json = Json.JsonSerializer.Serialize(instance); |
| 30 | return (T)Json.JsonSerializer.Deserialize(json, instance.GetType()); |
| 31 | } |
| 32 | |
| 33 | /// <summary> |
| 34 | /// Creates raw clone for a structure using memory copy. Valid only for value types. |
no test coverage detected