Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C# extension method for fast object cloning. This is a speed-optimized forked version of Alexy Burtsev's deep copier.

License

NotificationsYou must be signed in to change notification settings

jpmikkers/Baksteen.Extensions.DeepCopy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 theinner loops
  • use a compiled lamba expression to call MemberwiseClone

How to use:

Use NuGet package manager to add the packageBaksteen.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)

About

C# extension method for fast object cloning. This is a speed-optimized forked version of Alexy Burtsev's deep copier.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C#100.0%

[8]ページ先頭

©2009-2025 Movatter.jp