MintPlayer.SourceGenerators.Tools
10.21.0
dotnet add package MintPlayer.SourceGenerators.Tools --version 10.21.0
NuGet\Install-Package MintPlayer.SourceGenerators.Tools -Version 10.21.0
<PackageReference Include="MintPlayer.SourceGenerators.Tools" Version="10.21.0" />
<PackageVersion Include="MintPlayer.SourceGenerators.Tools" Version="10.21.0" />
<PackageReference Include="MintPlayer.SourceGenerators.Tools" />
paket add MintPlayer.SourceGenerators.Tools --version 10.21.0
#r "nuget: MintPlayer.SourceGenerators.Tools, 10.21.0"
#:package MintPlayer.SourceGenerators.Tools@10.21.0
#addin nuget:?package=MintPlayer.SourceGenerators.Tools&version=10.21.0
#tool nuget:?package=MintPlayer.SourceGenerators.Tools&version=10.21.0
MintPlayer.SourceGenerators.Tools
This package makes it easier to write your own source-generators. The library provides:
- An
IncrementalGeneratorclass that implementsIIncrementalGeneratorand already reads several options (like theRootNamespaceof the project) beforehand) - A
Producerclass that hands you a ready-to-useIndentedTextWriter - 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.
| Product | Versions 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. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 5.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MintPlayer.SourceGenerators.Tools:
| Package | Downloads |
|---|---|
|
MintPlayer.ValueComparers.NewtonsoftJson
Value-comparer for Newtonsoft.Json JObject, so incremental source generators carrying JObject in their models still cache correctly |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.21.0 | 59 | 8/27/2026 |
| 10.20.1 | 65 | 8/27/2026 |
| 10.20.0 | 770 | 6/5/2026 |
| 10.19.0 | 909 | 4/3/2026 |
| 10.16.0 | 550 | 2/22/2026 |
| 10.15.0 | 193 | 2/8/2026 |
| 10.14.0 | 209 | 1/19/2026 |
| 10.13.0 | 1,295 | 1/19/2026 |
| 10.11.0 | 128 | 1/19/2026 |
| 10.10.2 | 136 | 1/18/2026 |
| 10.10.1 | 343 | 1/12/2026 |
| 10.10.0 | 214 | 1/12/2026 |
| 10.9.0 | 219 | 1/12/2026 |
| 10.8.0 | 285 | 12/24/2025 |
| 10.7.0 | 401 | 11/13/2025 |
| 10.5.0 | 574 | 11/11/2025 |
| 10.4.0 | 392 | 11/10/2025 |
| 10.3.0 | 324 | 11/6/2025 |
| 10.2.0 | 298 | 11/6/2025 |
| 10.1.0 | 294 | 11/5/2025 |