MintPlayer.ValueComparerGenerator
10.20.2
dotnet add package MintPlayer.ValueComparerGenerator --version 10.20.2
NuGet\Install-Package MintPlayer.ValueComparerGenerator -Version 10.20.2
<PackageReference Include="MintPlayer.ValueComparerGenerator" Version="10.20.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="MintPlayer.ValueComparerGenerator" Version="10.20.2" />
<PackageReference Include="MintPlayer.ValueComparerGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add MintPlayer.ValueComparerGenerator --version 10.20.2
#r "nuget: MintPlayer.ValueComparerGenerator, 10.20.2"
#:package MintPlayer.ValueComparerGenerator@10.20.2
#addin nuget:?package=MintPlayer.ValueComparerGenerator&version=10.20.2
#tool nuget:?package=MintPlayer.ValueComparerGenerator&version=10.20.2
Value-comparer generator
This library contains source-generators to simplify writing your own source-generators.
Getting started
You need to install both MintPlayer.ValueComparerGenerator and MintPlayer.ValueComparerGenerator packages in your project.
Example
Note that the class (and parent classes) must be partial.
using MintPlayer.ValueComparerGenerator.Attributes;
namespace ValueComparerDebugging.Models;
public partial class Context
{
public partial class Models
{
[AutoValueComparer]
public partial class Person
{
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public List<Address> Addresses { get; set; } = [];
}
[AutoValueComparer]
public partial class Address
{
public string Street { get; set; } = string.Empty;
public int Number { get; set; }
public string City { get; set; } = string.Empty;
public int PostalCode { get; set; }
[ComparerIgnore]
public string Text { get; set; }
}
}
}
WithComparer
The source generator also generates a .WithComparer() and .WithNullableComparer() extension method that doesn't require parameters. This allows you to minimize your source-generator code like this:
[Generator(LanguageNames.CSharp)]
public class MapperGenerator : IncrementalGenerator
{
public override void Initialize(IncrementalGeneratorInitializationContext context, IncrementalValueProvider<Settings> settingsProvider)
{
var typesToMapProvider = context.SyntaxProvider
.ForAttributeWithMetadataName(
"MintPlayer.Mapper.Attributes.GenerateMapperAttribute",
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() == "MintPlayer.Mapper.Attributes.GenerateMapperAttribute") is { ConstructorArguments.Length: > 0 } attr &&
attr.ConstructorArguments.FirstOrDefault().Value is INamedTypeSymbol mapType)
{
return new Models.TypeToMap
{
...
};
}
return null;
}
)
.WithComparer(); // <-- No need to pass in the reference to the value-comparer
var typesToMapSourceProvider = typesToMapProvider
.Select(static Producer (p, ct) => new MapperProducer(p));
context.ProduceCode(typesToMapSourceProvider);
}
public override void RegisterComparers()
{
}
}
Joining providers
The MintPlayer.SourceGenerators.Tools package already contains 4 extension methods that help you join providers.
var typeTreeSourceProvider = typeProvider
.Join(typeTreeProvider)
.Join(childrenWithoutDerived)
.Join(settingsProvider)
.Join(hasCodeAnalysisReference)
.Select(static Producer (p, ct) => new Producers.TreeValueComparerProducer(
p.Item1.Where(t => t.HasAutoValueComparerAttribute),
p.Item2,
p.Item3,
p.Item4.RootNamespace!,
valueComparerType,
valueComparerAttributeType,
p.Item5
));
By using this extension method, you can avoid the nested tuples that would require you to write p.Left.Left.Left.Left.Right to access a value.
If you want to join more than 5 providers, you can apply the [assembly: GenerateJoinMethods(n)] attribute on a namespace.
The ValueComparerGenerator package contains a source-generator that will generate the necessary extension methods for you.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- MintPlayer.ValueComparerGenerator.Attributes (>= 10.20.1)
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 |
|---|---|---|
| 10.20.2 | 40 | 9/3/2026 |
| 10.20.1 | 86 | 8/27/2026 |
| 10.20.0 | 533 | 6/5/2026 |
| 10.19.0 | 703 | 4/3/2026 |
| 10.13.0 | 131 | 1/19/2026 |
| 10.10.1 | 123 | 1/12/2026 |
| 10.10.0 | 140 | 1/12/2026 |
| 10.9.0 | 130 | 1/12/2026 |
| 10.8.0 | 212 | 12/24/2025 |
| 10.7.0 | 307 | 11/13/2025 |
| 10.5.0 | 331 | 11/11/2025 |
| 10.4.0 | 300 | 11/10/2025 |
| 10.3.0 | 223 | 11/6/2025 |
| 10.2.0 | 226 | 11/6/2025 |
| 10.1.0 | 216 | 11/5/2025 |
| 10.0.1 | 229 | 11/2/2025 |
| 10.0.0 | 229 | 11/2/2025 |
| 10.0.0-preview.2 | 115 | 11/1/2025 |
| 10.0.0-preview.1 | 104 | 11/1/2025 |
| 9.2.1 | 201 | 10/31/2025 |