ShereSoft.DeepCloning
1.0.0
This version has critical bugs. Please update to the latest version. There are not breaking changes.
See the version list below for details.
dotnet add package ShereSoft.DeepCloning --version 1.0.0
NuGet\Install-Package ShereSoft.DeepCloning -Version 1.0.0
<PackageReference Include="ShereSoft.DeepCloning" Version="1.0.0" />
paket add ShereSoft.DeepCloning --version 1.0.0
#r "nuget: ShereSoft.DeepCloning, 1.0.0"
// Install ShereSoft.DeepCloning as a Cake Addin
#addin nuget:?package=ShereSoft.DeepCloning&version=1.0.0
// Install ShereSoft.DeepCloning as a Cake Tool
#tool nuget:?package=ShereSoft.DeepCloning&version=1.0.0
Provides a set of methods to deep-copy an instance of any object. Implemented in Common Intermediate Language (.NET Assembly) offering performance equivalent to hand-written code. No library dependencies.
- Can deep-clone instances of any object
- Implemented in Common Intermediate Language (.NET Assembly), compiled for each type at runtime, and cached for subsequent use.
- No use of Reflection for cloning
- Configurable for string handling (deep clone or not) and singleton handling (reuse or clone)
- Thread-safe
- Includes extension methods (ObjectExtensions) for conveniently calling from any object instance (Recommended usage)
- Unit Tested
- Multi-targeted (.NET 6, .NET 5, .NET Core 3.1, .NET Framework 4.5)
- No external library dependencies
- No external calls
QUICK START
Using the extension methods (included) is recommended.
.DeepClone()
using ShereSoft.Extensions;
:
Customer customer = new Customer();
:
Customer clone = customer.DeepClone();
DeepCloningOptions
.DeepCloneStrings = true
var customer = new Customer();
customer.Name = "John";
var options = new DeepCloningOptions { DeepCloneStrings = true };
Customer clone = customer.DeepClone(options);
Debug.WriteLine(Object.ReferenceEquals(customer, clone)); // False (Default returns True)
Strings are reused by default as they are normally treated as immutable. If your code contains any string manipulation by pointer, use this option to prevent unwanted side effects to the original object.
.DeepCloneSingletons = true
class Customer
{
public static readonly Customer Empty = new Customer(); // Static readonly fields as singletons
:
}
var customer = Customer.Empty;
var options = new DeepCloningOptions { DeepCloneSingletons = true };
Customer clone = customer.DeepClone(options);
Debug.WriteLine(Object.ReferenceEquals(customer, clone)); // False (Default returns True)
"static readonly" fields are assumed to be immutable. If your code is not, which by the way is not the best practice, use this option.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
This is a Beta release.