ShereSoft.DeepCloning 1.0.0

Additional Details

This version has critical bugs. Please update to the latest version. There are not breaking changes.

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ShereSoft.DeepCloning --version 1.0.0
NuGet\Install-Package ShereSoft.DeepCloning -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShereSoft.DeepCloning" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShereSoft.DeepCloning --version 1.0.0
#r "nuget: ShereSoft.DeepCloning, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
1.1.1 3,713 10/3/2022
1.1.0 630 3/7/2022
1.0.2 424 3/4/2022

This is a Beta release.