MintPlayer.SourceGenerators.Tools 11.0.0

Additional Details

Assembly version is incorrect

There is a newer version of this package available.
See the version list below for details.
dotnet add package MintPlayer.SourceGenerators.Tools --version 11.0.0
                    
NuGet\Install-Package MintPlayer.SourceGenerators.Tools -Version 11.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="MintPlayer.SourceGenerators.Tools" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MintPlayer.SourceGenerators.Tools" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MintPlayer.SourceGenerators.Tools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MintPlayer.SourceGenerators.Tools --version 11.0.0
                    
#r "nuget: MintPlayer.SourceGenerators.Tools, 11.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.
#:package MintPlayer.SourceGenerators.Tools@11.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MintPlayer.SourceGenerators.Tools&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MintPlayer.SourceGenerators.Tools&version=11.0.0
                    
Install as a Cake Tool

MintPlayer.SourceGenerators.Tools

This package makes it easier to write your own source-generators. The library provides:

  • An IncrementalGenerator class that implements IIncrementalGenerator and already reads several options (like the RootNamespace of the project) beforehand)
  • A Producer class that hands you a ready-to-use IndentedTextWriter
  • A ProduceCode(...) extension method where you can pass in your source-providers

Example

Generator:

namespace ExampleGenerators;

// Use the ready-made IncrementalGenerator

[Generator(LanguageNames.CSharp)]
public class ExampleGenerator : IncrementalGenerator
{
    public override void Initialize(IncrementalGeneratorInitializationContext context, IncrementalValueProvider<Settings> settingsProvider)
    {
        var typesToMapProvider = context.SyntaxProvider
            .ForAttributeWithMetadataName(
                "ExampleGenerators.Attributes.ExampleAttribute",
                static (node, ct) => node is not null,
                static (ctx, ct) =>
                {
                    if (ctx.SemanticModel.GetDeclaredSymbol(ctx.TargetNode, ct) is INamedTypeSymbol typeSymbol &&
                        ctx.Attributes.FirstOrDefault(a => a.AttributeClass?.ToDisplayString() == "ExampleGenerators.Attributes.ExampleAttribute") is { } attr &&
                        attr.ConstructorArguments.FirstOrDefault().Value is INamedTypeSymbol mapType)
                    {
                        return new Models.TypeToMap
                        {
                            ...
                        };
                    }
                    return null;
                }
            )
            .WithComparer();

        var typesToMapSourceProvider = typesToMapProvider
            .Select(static Producer (p, ct) => new MapperProducer(p));

        // Pass your source-providers to the ready-made ProduceCode extension method 
        context.ProduceCode(typesToMapSourceProvider);
    }

    public override void RegisterComparers()
    {
        // Use this if you're using libraries like Newtonsoft.Json
        // Make sure to use a Mutex.
        // An example is available in NewtonsoftJsonComparers.Register()
    }
}

Producer:

public sealed class MapperProducer : Producer
{
    private readonly IEnumerable<TypeToMap> typesToMap;
    public MapperProducer(IEnumerable<TypeToMap> typesToMap, string rootNamespace) : base(rootNamespace, "Mappers.g.cs")
    {
        this.typesToMap = typesToMap;
    }

    protected override void ProduceSource(IndentedTextWriter writer, CancellationToken cancellationToken)
    {
        writer.WriteLine($"namespace {RootNamespace}");
        writer.WriteLine("{");
        writer.Indent++;

        writer.WriteLine("public static class MapperExtensions");
        writer.WriteLine("{");
        writer.Indent++;

        // Generate more code based on the data in typesToMap

        writer.Indent--;
        writer.WriteLine("}");

        writer.Indent--;
        writer.WriteLine("}");
    }
}

Use the ValueComparerGenerator

If you install this package too in your project, you can have your value-comparers automatically generated for you.

TypeToMap.cs

namespace MintPlayer.Mapper.Models;

[AutoValueComparer]
public partial class TypeToMap
{
    public string DeclaredType { get; set; }
    public string DeclaredTypeName { get; set; }
    public PropertyDeclaration[] DeclaredProperties { get; set; } = [];
    public string MappingType { get; set; }
    public string MappingTypeName { get; set; }
    public PropertyDeclaration[] MappingProperties { get; set; } = [];
    public string DestinationNamespace { get; set; }
}

This generator will generate a value-comparer and a .WithComparer() and .WithNullableComparer() extension method for you.

Staying incremental

A generator that emits the same output on every keystroke is still doing the work on every keystroke. The pieces above are built so that an edit your generator does not care about stops at a comparer:

  • ProduceCode(...) gives each producer its own output step and never touches the Compilation, so a file is regenerated only when its own producer's input changed. Since 11.0.0; before that every producer was combined with the Compilation and re-ran on every edit.
  • [ValueComparer(typeof(...))] (which [AutoValueComparer] emits for you) is honoured by ComparerRegistry, so .WithComparer() and nested comparisons use your comparer without manual registration. Arrays, List<T> and ImmutableArray<T> compare element-wise.
  • ReportDiagnostics(...) needs the Compilation to rebuild in-tree locations, which #pragma and .editorconfig severity depend on. Implement IConditionalDiagnosticReporter and a reporter with nothing to report runs no step at all.

Rules of thumb for your models: no ISymbol, SyntaxNode, SyntaxTokenList, Location or Compilation (use strings and LocationKey); put .WithComparer() on every step that produces a model, especially before Collect(); and carry a LocationKey only on a model that will actually report a diagnostic, so that typing above a declaration does not invalidate it.

To prove it, MintPlayer.SourceGenerators.Testing runs a generator twice and reports the run reason of every output step.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
12.1.0 104 9/26/2026
12.0.1 65 9/25/2026 12.0.1 is deprecated.
12.0.0 67 9/25/2026 12.0.0 is deprecated.
11.0.0 71 9/25/2026 11.0.0 is deprecated.
10.21.0 477 8/27/2026
10.20.1 152 8/27/2026
10.20.0 962 6/5/2026
10.19.0 918 4/3/2026
10.16.0 565 2/22/2026
10.15.0 197 2/8/2026
10.14.0 212 1/19/2026
10.13.0 1,338 1/19/2026
10.11.0 133 1/19/2026
10.10.2 140 1/18/2026
10.10.1 349 1/12/2026
10.10.0 217 1/12/2026
10.9.0 225 1/12/2026
10.8.0 288 12/24/2025
10.7.0 405 11/13/2025
10.5.0 576 11/11/2025
Loading failed