Moongazing.OrionGuard.Generators 6.1.0

Suggested Alternatives

OrionGuard.Generators

dotnet add package Moongazing.OrionGuard.Generators --version 6.1.0
                    
NuGet\Install-Package Moongazing.OrionGuard.Generators -Version 6.1.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="Moongazing.OrionGuard.Generators" Version="6.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Moongazing.OrionGuard.Generators" Version="6.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Moongazing.OrionGuard.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 Moongazing.OrionGuard.Generators --version 6.1.0
                    
#r "nuget: Moongazing.OrionGuard.Generators, 6.1.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 Moongazing.OrionGuard.Generators@6.1.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=Moongazing.OrionGuard.Generators&version=6.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Moongazing.OrionGuard.Generators&version=6.1.0
                    
Install as a Cake Tool

Moongazing.OrionGuard.Generators

Roslyn incremental source generators for OrionGuard. Generates zero-reflection, NativeAOT-compatible validators and strongly-typed ID types from attributes.

What this package generates

[GenerateValidator] — compile-time validator

Add validation attributes to a DTO and the generator emits a static Validate(...) method that runs at compile-time speed without reflection.

[GenerateValidator]
public sealed class CreateUserRequest
{
    [NotNull, NotEmpty, Length(3, 50)] public string Name { get; set; } = default!;
    [NotNull, Email]                   public string Email { get; set; } = default!;
    [Range(13, 120)]                   public int Age { get; set; }
}

var result = CreateUserRequestValidator.Validate(request);

[StronglyTypedId<TValue>] — strongly-typed identifiers (new in v6.1)

Mark a readonly partial struct and the generator emits four companion sources:

  • Partial struct body — IEquatable<T>, operators, GetHashCode, ToString, Value property, constructor, and (for Guid/Ulid) New() / Empty.
  • EF Core ValueConverter<TId, TValue>.
  • System.Text.Json JsonConverter<TId> with per-type Read/Write.
  • System.ComponentModel TypeConverter (for ASP.NET Core route/query/form binding).
[StronglyTypedId<Guid>]
public readonly partial struct OrderId;

[StronglyTypedId<int>]
public readonly partial struct SkuId;

[StronglyTypedId<string>]
public readonly partial struct CountryCode;

Supported underlying types: System.Guid, int, long, string, System.Ulid (net9.0+).

Install

dotnet add package Moongazing.OrionGuard.Generators

This package is an analyzer/source-generator reference — it contributes generated code at compile time and does not add runtime dependencies to your output.

Register EF Core converters

The generated EF Core ValueConverters can be registered in DI with a single call from the core OrionGuard package:

using Moongazing.OrionGuard.DependencyInjection;

services.AddOrionGuardStronglyTypedIds(); // scans the calling assembly

Roslyn analyzers shipped

Id Description
OG0001 Missing validation attribute — emitted by MissingValidationAnalyzer when a parameter looks like it should be validated but isn't.

Targets

netstandard2.0 (Roslyn-compatible). Consumes any net8.0+ project.

License

MIT. See the main repository for full docs, CHANGELOG, and samples.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • 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
6.1.0 147 4/19/2026 6.1.0 is deprecated because it is no longer maintained and has critical bugs.