ZeroAlloc.Validation
0.1.2
See the version list below for details.
dotnet add package ZeroAlloc.Validation --version 0.1.2
NuGet\Install-Package ZeroAlloc.Validation -Version 0.1.2
<PackageReference Include="ZeroAlloc.Validation" Version="0.1.2" />
<PackageVersion Include="ZeroAlloc.Validation" Version="0.1.2" />
<PackageReference Include="ZeroAlloc.Validation" />
paket add ZeroAlloc.Validation --version 0.1.2
#r "nuget: ZeroAlloc.Validation, 0.1.2"
#:package ZeroAlloc.Validation@0.1.2
#addin nuget:?package=ZeroAlloc.Validation&version=0.1.2
#tool nuget:?package=ZeroAlloc.Validation&version=0.1.2
ZeroAlloc.Validation
Source-generated, attribute-based validation for .NET that allocates nothing on the valid path. The source generator emits a strongly-typed validator class at build time — no reflection at runtime. When all rules pass, the entire validation cycle produces zero heap allocations.
Install
dotnet add package ZeroAlloc.Validation
30-Second Example
using ZeroAlloc.Validation;
[Validate]
public class CreateOrderRequest
{
[NotEmpty][MaxLength(50)] public string Reference { get; set; } = "";
[GreaterThan(0)] public decimal Amount { get; set; }
[NotEmpty][EmailAddress] public string Email { get; set; } = "";
}
// The source generator emits CreateOrderRequestValidator at build time
var request = new CreateOrderRequest
{
Reference = "ORD-2026-001",
Amount = 99.99m,
Email = "customer@example.com"
};
var validator = new CreateOrderRequestValidator();
var result = validator.Validate(request);
if (!result.IsValid)
foreach (ref readonly var f in result.Failures)
Console.WriteLine($"{f.PropertyName}: {f.ErrorMessage}");
Performance
| Scenario | ZeroAlloc.Validation | FluentValidation | Speedup | Allocation (valid) |
|---|---|---|---|---|
| Flat model | 6.7 ns | 327 ns | ~49× | 0 B |
| Nested model | 10.1 ns | 619 ns | ~61× | 0 B |
| Collection (3×) | 14.3 ns | 2,043 ns | ~143× | 0 B |
See Performance for full benchmark results.
Features
- Zero heap allocation on the valid path
- 25+ built-in validation attributes
- Nested object and collection validation
- ASP.NET Core auto-validation (HTTP 422 on failure)
- Per-rule severity (
Error,Warning,Info) - Conditional rules (
When/Unless/[SkipWhen]) - Short-circuit with
[StopOnFirstFailure] - Custom rules via
[Must]predicates or[CustomValidation]methods - Testing helpers via
ZeroAlloc.Validation.Testing
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
net10.0
- ZeroAlloc.Pipeline (>= 0.1.1)
-
net8.0
- ZeroAlloc.Pipeline (>= 0.1.1)
-
net9.0
- ZeroAlloc.Pipeline (>= 0.1.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ZeroAlloc.Validation:
| Package | Downloads |
|---|---|
|
ZeroAlloc.Validation.AspNetCore
ASP.NET Core integration for ZeroAlloc.Validation. Source-generated action filter validates request models at compile time with zero runtime overhead. |
|
|
ZeroAlloc.Validation.Testing
Testing helpers for ZeroAlloc.Validation. Provides assertion utilities to verify validation results in unit tests. |
GitHub repositories
This package is not used by any popular GitHub repositories.