Skelp.MirrorClone 1.1.0

There is a newer version of this package available.
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                
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="Skelp.MirrorClone" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Skelp.MirrorClone --version 1.1.0                
#r "nuget: Skelp.MirrorClone, 1.1.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 Skelp.MirrorClone as a Cake Addin
#addin nuget:?package=Skelp.MirrorClone&version=1.1.0

// Install Skelp.MirrorClone as a Cake Tool
#tool nuget:?package=Skelp.MirrorClone&version=1.1.0                

<img src="/misc/icon.png" width="32" height="32"> MirrorClone License: MIT Nuget

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.

  1. Skelp.MirrorClone consists of the actual Cloner class
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
1.1.1 422 3/29/2022
1.1.0 255 1/4/2022
1.0.0 229 12/30/2021