Baksteen.Extensions.DeepCopy 1.0.4

dotnet add package Baksteen.Extensions.DeepCopy --version 1.0.4                
NuGet\Install-Package Baksteen.Extensions.DeepCopy -Version 1.0.4                
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="Baksteen.Extensions.DeepCopy" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Baksteen.Extensions.DeepCopy --version 1.0.4                
#r "nuget: Baksteen.Extensions.DeepCopy, 1.0.4"                
#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 Baksteen.Extensions.DeepCopy as a Cake Addin
#addin nuget:?package=Baksteen.Extensions.DeepCopy&version=1.0.4

// Install Baksteen.Extensions.DeepCopy as a Cake Tool
#tool nuget:?package=Baksteen.Extensions.DeepCopy&version=1.0.4                

C# extension method for fast object cloning.

Nuget

This is a speed-optimized fork of Alexey Burtsev's deep copier. Depending on your usecase, this will be 2x - 3x faster than the original. It also fixes some bugs which are present in the original code. Compared to the classic binary serialization/deserialization deep clone technique, this version is about seven times faster (the more arrays your objects contain, the bigger the speedup factor).

The speedup is achieved via the following techniques:

  • object reflection results are cached
  • don't deep copy primitives or immutable structs & classes (e.g. enum and string)
  • to improve locality of reference, process the 'fast' dimensions or multidimensional arrays in the inner loops
  • use a compiled lamba expression to call MemberwiseClone

How to use:

Use NuGet package manager to add the package Baksteen.Extensions.DeepCopy to your project. Then:

using Baksteen.Extensions.DeepCopy;
...
var myobject = new SomeClass();
...
var myclone = myobject.DeepCopy()!;    // creates a new deep copy of the original object 

Note: the exclamation mark (null-forgiving operator) is only required if you enabled nullable reference types in your project

Contributors:

  • Alexey Burtsev (original deep copy code)
  • Wouter Groeneveld (unit tests & XElement copy)
  • Gitkarst (treat enum as immutable)
  • Jean-Paul Mikkers (speed optimization)
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Baksteen.Extensions.DeepCopy:

Package Downloads
ScapeCore.Core.Engine

Main engine types from ScapeCore repository.

ScapeCore.Core.Serialization

Serializer used in ScapeCore. It uses protocol buffers with optional gZip compression.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 215 11/19/2024
1.0.3 17,700 11/15/2023
1.0.2 22,784 11/8/2022
1.0.1 577 9/17/2022
1.0.0 450 3/18/2022

Added net9 support, removed net7. Speed up copy of other System.Numerics types