Skelp.MirrorClone
1.1.0
See the version list below for details.
dotnet add package Skelp.MirrorClone --version 1.1.0
NuGet\Install-Package Skelp.MirrorClone -Version 1.1.0
<PackageReference Include="Skelp.MirrorClone" Version="1.1.0" />
<PackageVersion Include="Skelp.MirrorClone" Version="1.1.0" />
<PackageReference Include="Skelp.MirrorClone" />
paket add Skelp.MirrorClone --version 1.1.0
#r "nuget: Skelp.MirrorClone, 1.1.0"
#addin nuget:?package=Skelp.MirrorClone&version=1.1.0
#tool nuget:?package=Skelp.MirrorClone&version=1.1.0
<img src="/misc/icon.png" width="32" height="32"> MirrorClone

This repository provides a reflection-based cloner which copies over anything it can find while also considering the original object references (eg. two child-objects having the same reference to the parent object).
No class-attributes required.
Supported Types
Generally speaking, everything imaginable should be clonable.
However, instances of the following have been covered by tests.
- primitives
- strings
- classes
- structs
- arrays (inluding ragged- and multidimensional arrays)
- collections (
List
,Dictionary
) - delegates (
Func
) - null
- dynamic (
ExpandoObject
)
Should you find something which refuses to be cloned, please raise an issue in this repository.
Installation
Simply use the Visual Studio NuGet Package Manager and look for MirrorClone
.
Alternatively, you can use the Package Manager Console as such:
Install-Package Skelp.MirrorClone
If you want to use the .NET CLI, you can use the following command:
dotnet add package Skelp.MirrorClone
Getting Started
The package consists of of two namespaces.
- Skelp.MirrorClone consists of the actual
Cloner
class - Skelp.MirrorClone.Extensions provides
object
extensions
Choose either of them to get started.
Using The object
Extensions
using Skelp.MirrorClone.Extensions;
[...]
YourObject objectToClone = new YourObject();
// This is what will be called 99.9% of the time
var clonedObject = objectToClone.MirrorClone();
// Alternatively, if object is deeply nested and presents stack overflow concerns
// this will catch any stack overflow from crashing the application
bool success = objectToClone.TryMirrorClone(out YourObject clonedObject);
Using The Cloner
Class
using Skelp.MirrorClone;
[...]
YourObject objectToClone = new YourObject();
var cloner = new Cloner();
// This is what will be called 99.9% of the time
var clonedObject = cloner.Clone(objectToClone);
// Alternatively, if object is deeply nested and presents stack overflow concerns
// this will catch any stack overflow from crashing the application
bool success = cloner.TryClone(objectToClone, out YourObject clonedObject);
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- 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.