Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mostmand/Cloneable
Auto generate Clone method using C# Source Generator
https://github.com/mostmand/Cloneable
csharp-sourcegenerator
Last synced: about 1 month ago
JSON representation
Auto generate Clone method using C# Source Generator
- Host: GitHub
- URL: https://github.com/mostmand/Cloneable
- Owner: mostmand
- Created: 2020-09-25T23:22:51.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-01T02:16:34.000Z (over 1 year ago)
- Last Synced: 2024-08-01T22:43:52.174Z (4 months ago)
- Topics: csharp-sourcegenerator
- Language: C#
- Homepage:
- Size: 53.7 KB
- Stars: 70
- Watchers: 3
- Forks: 10
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- csharp-source-generators - Cloneable - ![stars](https://img.shields.io/github/stars/mostmand/Cloneable?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/mostmand/Cloneable?style=flat-square&cacheSeconds=86400) auto-generate Clone method. (Source Generators / Other)
- RSCG_Examples - Cloneable
README
# Cloneable
Auto generate Clone method using C# Source GeneratorThere 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](https://www.nuget.org/packages/Cloneable):Install-Package Cloneable
Or via the .NET Core command line interface:dotnet add package Cloneable
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:
```csharp
[Cloneable]
public partial class Foo
{
public string A { get; set; }
public int B { get; set; }
}
```For more examples please visit the [sample project](https://github.com/mostmand/Cloneable/tree/master/Cloneable.Sample).