Cloneable.Generator 2.0.0

dotnet add package Cloneable.Generator --version 2.0.0                
NuGet\Install-Package Cloneable.Generator -Version 2.0.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="Cloneable.Generator" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cloneable.Generator --version 2.0.0                
#r "nuget: Cloneable.Generator, 2.0.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 Cloneable.Generator as a Cake Addin
#addin nuget:?package=Cloneable.Generator&version=2.0.0

// Install Cloneable.Generator as a Cake Tool
#tool nuget:?package=Cloneable.Generator&version=2.0.0                

Cloneable

This is a fork of https://github.com/mostmand/Cloneable - Which doesn't seem to be maintained...

Auto generate Clone method using C# Source Generator

There are times you want to make a clone of an object. You can implement a clone method, but when a developer adds a new Field or Property the clone method should be changed too. Another way is to use reflection which is not performant. This source generator saves your time by generating the boilerplate code for cloning an object.

Installing Cloneable

You should install Cloneable with NuGet:

Install-Package Cloneable.Generator

Or via the .NET Core command line interface:

dotnet add package Cloneable.Generator

Either commands, from Package Manager Console or .NET Core CLI, will download and install Cloneable and all required dependencies.

Usage

You can add clone method to a class by making it partial and adding the attribute Cloneable on top of it. An example is provided in Cloneable.Sample project.

Source generators are introduced in dotnet 5.0. So make sure to have Visual Studio 16.8 or dotnet 5.0 sdk installed.

Here is a simple example:

[Cloneable]
public partial class Foo
{
    public string A { get; set; }
    public int B { get; set; }
}

For more examples please visit the sample project. Or view some of the tests test project.

There are no supported framework assets in this 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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 304 5/10/2023