eQuantic.Validation.Generator 2.2.0

dotnet add package eQuantic.Validation.Generator --version 2.2.0
                    
NuGet\Install-Package eQuantic.Validation.Generator -Version 2.2.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="eQuantic.Validation.Generator" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="eQuantic.Validation.Generator" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="eQuantic.Validation.Generator" />
                    
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 eQuantic.Validation.Generator --version 2.2.0
                    
#r "nuget: eQuantic.Validation.Generator, 2.2.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 eQuantic.Validation.Generator@2.2.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=eQuantic.Validation.Generator&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=eQuantic.Validation.Generator&version=2.2.0
                    
Install as a Cake Tool

eQuantic.Validation.Generator

Incremental Roslyn source generator and usage analyzer for eQuantic.Validation. Trimming- and Native AOT-friendly: no reflection, no MakeGenericType, no runtime expression compilation.

<PackageReference Include="eQuantic.Validation.Generator"
                  PrivateAssets="all"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />

Install it in every project that declares models with [GenerateValidator] or fluent validators.

What it generates

1. Reflection-free validators for annotated models:

[GenerateValidator]
public sealed record CreateCustomer(
    [Required, NotWhiteSpace] string Name,
    [Required, Email(Code = "customer.email.invalid")] string Email,
    [Range(18, 120)] int Age);
// → CreateCustomerGeneratedValidator : IValidator<CreateCustomer>, IDescribableValidator

2. Compile-time DI registration — AddGeneratedValidation() is generated internal to the compiling assembly and registers only that assembly's validators as scoped services. Referenced assemblies are never scanned; compose them explicitly with AddValidator<TModel, TValidator>().

builder.Services.AddGeneratedValidation();

3. Pre-compiled fluent accessors — every RuleFor(x => x.Prop) lambda in your Validator<T> subclasses is compiled at build time and registered at module load. The fluent path never pays Expression.Compile() at runtime (validators are scoped, so that cost used to repeat per request) and never runs through the expression interpreter under Native AOT.

Compile-time diagnostics

ID Severity Example that triggers it Fix
VALGEN001 Warning AddGeneratedValidation() without the core + DI abstractions packages reference eQuantic.Validation
VALGEN002 Error [CustomRule("Missing")] — no such bool method declare bool Missing(string? value) on the model
VALGEN003 Warning [ValidateEach] string Name — not IEnumerable<T> apply to collections only
VALGEN004 Warning [Email] int Age — string rule on non-string move the rule to a string property
VALGEN005 Error RuleFor(x => x.Name!.Trim()) — not a member path RuleFor(x => x.Name) and normalize elsewhere
VALGEN006 Error RuleFor(x => x.Name).WithMessage("...") — configurator with no rule add a rule first: .NotWhiteSpace().WithMessage("...")
VALGEN007 Warning validator.Validate(m) where the validator has unconditional MustAsync call ValidateAsync

VALGEN007 is scenario-aware: async rules scoped with .ForScenarios("create") don't flag synchronous validation.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
2.2.0 265 8/16/2026
2.1.0 110 8/16/2026
2.0.0 101 8/16/2026
1.0.0 107 8/16/2026

Initial incremental generator for compile-time validator DI registration.