https://github.com/ReubenBond/DeepCopy
Simple & efficient library for deep copying .NET objects
https://github.com/ReubenBond/DeepCopy
Last synced: about 1 year ago
JSON representation
Simple & efficient library for deep copying .NET objects
- Host: GitHub
- URL: https://github.com/ReubenBond/DeepCopy
- Owner: ReubenBond
- License: mit
- Created: 2017-11-03T06:14:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-14T09:31:00.000Z (over 2 years ago)
- Last Synced: 2025-04-12T17:46:32.886Z (about 1 year ago)
- Language: C#
- Size: 48.8 KB
- Stars: 226
- Watchers: 13
- Forks: 33
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DeepCopy
Simple & efficient library for deep copying .NET objects
Described in this blog post: https://reubenbond.github.io/posts/codegen-2-il-boogaloo
## Installation:
Install via NuGet:
```powershell
PM> Install-Package DeepCopy
```
## Usage:
```C#
// Add a using directive for DeepCopy.
var poco = new Poco();
var original = new[] { poco, poco };
var result = DeepCopier.Copy(original);
// The result is a copy of the original.
Assert.NotSame(original, result);
// Because both elements in the original array point to the same object,
// both elements in the copied array also point to the same object.
Assert.Same(result[0], result[1]);
```
Optionally, classes can be marked using the `[Immutable]` attribute to tell `DeepCopy` to skip copying them and return them unmodified.
Object can also be wrapped in `Immutable` using `Immutable.Create(value)`.
The majority of this project was adapted from [`dotnet/orleans`](https://github.com/dotnet/orleans).
PR's welcome!