Skip to main content

Zomp.MethodCloning.Variants by Zomp Inc.

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: Zomp.MethodCloning.Variants

A source generator which writes the variants of a method from the one written by hand: SaveAsBmp becomes SaveAsGif and SaveAsPng, with their types and documentation. Replaces T4 templates which stamp out the same method once per type.

Author: Zomp Inc.

NuGet: https://www.nuget.org/packages/Zomp.MethodCloning.Variants/

You can find more details at https://github.com/zompinc/method-cloning

Source: https://github.com/zompinc/method-cloning

Author​

note

Zomp Inc. Alt text

Original Readme​

note

Zomp.MethodCloning​

Roslyn source generators that copy methods, so you write each one once.

I want to...Use
Stop maintaining T4 templates that repeat a method per format or typeZomp.MethodCloning.Variants
Write my own generator that copies methods and changes themZomp.MethodCloning

Zomp.SyncMethodGenerator, which writes the sync version of async methods, is built on the same core.

Learn more​
  • Variants reference: every rule, the limitations, and migrating from T4.
  • AGENTS.md: how the repository is built and tested, and the rules the core's source files follow.
Build​
dotnet build
dotnet test

About​

note

Generate format, type, or mode variants from one written method.

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references Zomp.MethodCloning.Variants

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Zomp.MethodCloning.Variants" Version="1.0.24">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>
namespace Zomp.MethodCloning
{
/// <summary>
/// Writes variants of a method from the one written by hand. The word naming the variant the
/// method was written for is swapped for each of the others: in the name of the method, in the
/// types and static members it refers to, and in its documentation.
/// </summary>
/// <remarks>
/// Applied to a partial type, it marks every method in the same declaration of the type.
/// </remarks>
[global::System.AttributeUsage(
global::System.AttributeTargets.Method |
global::System.AttributeTargets.Class |
global::System.AttributeTargets.Struct |
global::System.AttributeTargets.Interface,
AllowMultiple = false,
Inherited = false)]
[global::System.Diagnostics.Conditional("ZOMP_METHOD_CLONING_ATTRIBUTES")]
internal sealed class CloneVariantsAttribute : global::System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="CloneVariantsAttribute"/> class.
/// </summary>
/// <param name="original">The word naming the variant the method is written for, such as <c>Bmp</c>.</param>
/// <param name="variants">The words naming the variants to write, such as <c>Gif</c> and <c>Png</c>.</param>
public CloneVariantsAttribute(string original, params string[] variants)
{
}
}
}

Useful​

Download Example (.NET C#)​

Share Zomp.MethodCloning.Variants​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Zomp.MethodCloning.Variants

Category "Templating" has the following generators:​

1 Gobie Nuget GitHub Repo stars 2023-08-22

2 InlineComposition Nuget GitHub Repo stars 2025-07-22

3 InterceptorTemplate Nuget GitHub Repo stars 2023-11-29

4 JKToolKit.TemplatePropertyGenerator Nuget GitHub Repo stars 2024-07-17

5 Microsoft.NET.Sdk.Razor.SourceGenerators 2023-04-16

6 NTypewriter Nuget GitHub Repo stars 2025-01-19

7 RazorBlade Nuget GitHub Repo stars 2023-04-16

8 RazorSlices Nuget GitHub Repo stars 2024-10-27

9 RSCG_IFormattable NugetNuget GitHub Repo stars 2024-06-29

10 RSCG_Templating NugetNuget GitHub Repo stars 2023-10-07

11 spreadcheetah Nuget GitHub Repo stars 2023-08-13

12 Tortuga.Shipwright Nuget GitHub Repo stars 2025-07-21

13 Zomp.MethodCloning.Variants Nuget GitHub Repo stars 2026-11-10

See category​

Templating