IDeepCloneable 0.0.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package IDeepCloneable --version 0.0.10
                    
NuGet\Install-Package IDeepCloneable -Version 0.0.10
                    
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="IDeepCloneable" Version="0.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IDeepCloneable" Version="0.0.10" />
                    
Directory.Packages.props
<PackageReference Include="IDeepCloneable" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IDeepCloneable --version 0.0.10
                    
#r "nuget: IDeepCloneable, 0.0.10"
                    
#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.
#:package IDeepCloneable@0.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IDeepCloneable&version=0.0.10
                    
Install as a Cake Addin
#tool nuget:?package=IDeepCloneable&version=0.0.10
                    
Install as a Cake Tool

IDeepCloneable

NuGet Version GitHub Actions Workflow Status

Automatic implementation of the IDeepCloneable<T> interface via source generators. For library authors.

Overview

Provides automatic generation of the DeepClone() method and IDeepCloneable<T> implementation for partial types marked with [DeepCloneable].

Benefits

While there are many similar libraries available, this library's key feature is that it generates the DeepClone() method as an implementation of the IDeepCloneable<T> interface.

By doing this:

  • Library authors can use DeepClone() without reflection (NativeAOT friendly)
  • Users are relieved of the burden of manual implementation
// 3rd-party library side
public void RegisterCloneMethod<T>()
{
    Func<T, T> cloneFunc = null;

    if(typeof(IDeepCloneable<T>).IsAssignableFrom(typeof(T))) {
        cloneFunc = obj => obj.DeepClone();
    }
    else {
        // fallback implementation
    }
}

// user side
[DeepCloneable]
public partial class MyModel { /* ... */ }

How to use

Basic Usage

Install the NuGet package IDeepCloneable to your project.

dotnet add package IDeepCloneable

Then mark a partial type with the [DeepCloneable] attribute.

using IDeepCloneable;

[DeepCloneable]
public partial class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

That's it! The DeepClone() method will be automatically generated and the generated partial type will implement IDeepCloneable<Person>.

// generated code (sample)
partial class Person : IDeepCloneable<Person>
{
    public Person DeepClone()
    {
        return new Person
        {
            Name = this.Name,
            Age = this.Age,
        };
    }
}

And you can use it like this:

var person1 = new Person { Name = "Alice", Age = 30 };
var person2 = person1.DeepClone();
person2.ShouldNotBeSameAs(person1);

Customize

As you can see from the generated code, you can simply implement the IDeepCloneable<T>.DeepClone() method yourself.

using IDeepCloneable;

public class Person : IDeepCloneable<Person>
{
    public string Name { get; set; }
    public int Age { get; set; }

    public Person DeepClone()
    {
        // your custom implementation
    }
}

Library Structure

This consists of two libraries.

IDeepCloneable

This is the library that defines the IDeepCloneable<T> interface and the [DeepCloneable] marker attribute.

namespace IDeepCloneable;
public sealed class DeepCloneableAttribute : Attribute;
public interface IDeepCloneable<T>
{
    T DeepClone();
}

Additionally, it will automatically reference the IDeepCloneable.Generator.

IDeepCloneable.Generator

This is the source generator library that automatically generates the IDeepCloneable<T>.DeepClone() method. There is no need to directly reference this library.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on IDeepCloneable:

Repository Stars
lofcz/FastCloner
The fastest deep cloning library for .NET – zero-config, works out of the box.
Version Downloads Last Updated
0.1.4 542 2/3/2026
0.1.3 110 2/2/2026
0.1.2 97 2/2/2026
0.1.1 113 2/1/2026
0.1.0 99 1/30/2026
0.0.27 125 1/12/2026
0.0.26 99 1/12/2026
0.0.25 100 1/12/2026
0.0.24 109 1/12/2026
0.0.23 102 1/12/2026
0.0.22 111 1/12/2026
0.0.21 106 1/11/2026
0.0.20 104 1/9/2026
0.0.10 105 1/6/2026
0.0.5 481 1/4/2026
0.0.4 112 1/2/2026
0.0.3 111 1/1/2026
0.0.2 466 12/31/2025
0.0.1 102 12/31/2025