Home

Awesome

<p align="center"> <a href="https://github.com/AnderssonPeter/Dolly"> <img src="icon_white.svg" alt="Logo" width="80" height="80"> </a> <h3 align="center">Dolly</h3> <p align="center"> Clone .net objects using source generation <br /> <br /> · <a href="https://github.com/AnderssonPeter/Dolly/issues">Report Bug</a> · <a href="https://github.com/AnderssonPeter/Dolly/issues">Request Feature</a> · </p> </p> <br />

NuGet version Nuget GitHub license

unit tests Testspace tests Coverage Status

Table of Contents

About The Project

Generate c# code to clone objects on the fly.

Getting Started

Example

[Clonable]
public partial class SimpleClass
{
    public string First { get; set; }
    public int Second { get; set; }
    [CloneIgnore]
    public float DontClone { get; set; }
}

Should generate

partial class SimpleClass : IClonable<SimpleClass>
{
    
    object ICloneable.Clone() => this.DeepClone();

    public SimpleClass DeepClone() =>
        new SimpleClass()
        {
            First = First,
            Second = Second
        };

    public SimpleClass ShallowClone() =>
        new SimpleClass()
        {
            First = First,
            Second = Second
        };
}

Benchmarks

MethodMeanErrorStdDevRatioRatioSDGen0Gen1Allocated
Dolly124.5 ns1.59 ns1.49 ns1.000.020.0362-608 B
DeepCloner457.7 ns7.01 ns6.56 ns3.680.070.0830-1392 B
CloneExtensions566.2 ns9.61 ns8.52 ns4.550.080.0896-1504 B
NClone4,308.0 ns62.01 ns58.01 ns34.610.610.51120.00768584 B
FastCloner15,310.6 ns221.85 ns207.52 ns123.002.160.3967-6800 B
AnyClone19,011.9 ns354.27 ns347.94 ns152.743.252.4414-41256 B