ReverseMutty 1.0.4
Use partial declarations instead
dotnet add package ReverseMutty --version 1.0.4
NuGet\Install-Package ReverseMutty -Version 1.0.4
<PackageReference Include="ReverseMutty" Version="1.0.4" />
<PackageVersion Include="ReverseMutty" Version="1.0.4" />
<PackageReference Include="ReverseMutty" />
paket add ReverseMutty --version 1.0.4
#r "nuget: ReverseMutty, 1.0.4"
#:package ReverseMutty@1.0.4
#addin nuget:?package=ReverseMutty&version=1.0.4
#tool nuget:?package=ReverseMutty&version=1.0.4
Warn: This project is currently for internal use only due to development time limits. Use at your own risk.
ReverseMutty
A simple source generator to create a record class automatically from your written class. Inspired by Mutty.
Usage
Add [GenerateImmutable] attribute on your original class, and then the generator will generate the record class with public properties in your original class.
Add [InImmutable] attribute on the methods of your original class, and then the methods will be copied into the new class.
For example:
[GenerateImmutable]
public class Examples
{
public string Name { get; init; }
public int Game { get; set; }
[InImmutable]
public bool IsMatch()
{
return Game.ToString() == Name;
}
}
Will generate:
// <auto-generated/>
#nullable enable
namespace ReverseMutty.Sample
{
public record ImmutableExamples
{
public string Name { get; init; }
public int Game { get; init; }
// Warn: Copied from Examples, please ensure the compilability (may need to change the accessibility or the original class)
public bool IsMatch()
{
return Game.ToString() == Name;
}
public Examples ToMutable()
{
return new Examples
{
Name = this.Name,
Game = this.Game,
};
}
}
public static class ExamplesImmutableExtensions
{
public static ImmutableExamples ToImmutable(this Examples source)
{
return new ImmutableExamples
{
Name = source.Name,
Game = source.Game,
};
}
}
}
Be cautious that ungeneratable properties used in the copied methods and converters will cause compile errors. In this situation, you have to change your implementations.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.