PineGuard.DataAnnotations 0.1.0-alpha.7

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

PineGuard.DataAnnotations

Every PineGuard rule as a [ValidationAttribute]. Declarative validation for MVC, Blazor, and anywhere .NET reads DataAnnotations.

PineGuard.DataAnnotations exposes every PineGuard rule — [Email], [HttpsUrl], [OwaspSafe], and the rest — as attributes that plug into the .NET validation infrastructure you already have. ASP.NET Core MVC model binding runs them on [FromBody] with [ApiController], Blazor EditForm renders errors via DataAnnotationsValidator, and Validator.TryValidateObject runs them anywhere else. Zero custom middleware, zero hand-rolled wiring.

DataAnnotations are the .NET idiom for input-model validation — request DTOs, view models, and Blazor form models. They're a perfect fit for Clean Architecture, where the always-valid-state principle holds at the Presentation boundary: model binding runs the attributes automatically, so by the time the DTO reaches your Application layer, the input is always valid.

One rule library. Every call site in your architecture. The same Must.Be.Email your services call and the same Guard.Against.NotEmail your domain constructors call power [Email] on your DTOs. No parallel dialects. No drift. When the rule changes, every layer changes with it.

Install

dotnet add package PineGuard.DataAnnotations

Targets net8.0, net10.0, and netstandard2.1. Depends on PineGuard.Core, PineGuard.MustClauses, and System.ComponentModel.DataAnnotations.

Examples

using PineGuard.DataAnnotations;

public sealed class CreateUserRequest
{
    // The four canonical rules, as [ValidationAttribute]s
    [NotNull, Email]
    public string Email { get; init; } = string.Empty;

    [NotNull, StrictEmail]
    public string StrictEmailAddress { get; init; } = string.Empty;

    [NotNull, OwaspSafe]
    public string UserInput { get; init; } = string.Empty;

    [NotNull, HttpsUrl]
    public string Callback { get; init; } = string.Empty;
}

Chain with built-in DataAnnotations

PineGuard attributes compose with every built-in System.ComponentModel.DataAnnotations attribute — [Required], [StringLength], [MaxLength], [Range], [RegularExpression], and the rest — so you can stack PineGuard content validators alongside length limits and .NET's idiomatic presence checks on the same property.

using System.ComponentModel.DataAnnotations;
using PineGuard.DataAnnotations;

public sealed class UpdateProfileRequest
{
    [Required]
    [MaxLength(256)]
    [HttpsUrl]
    public string Website { get; init; } = string.Empty;

    [Required]
    [StringLength(320)] // RFC 5321 email total-length limit
    [StrictEmail]
    public string CompanyEmail { get; init; } = string.Empty;

    [MaxLength(500)]
    [OwaspSafe]
    public string Bio { get; init; } = string.Empty;
}

Presence semantics: [Required] vs [NotNull] vs [Null]

Both PineGuard and built-in DataAnnotations cover presence, with slightly different semantics:

  • [Required] (built-in) — rejects null and empty string (unless AllowEmptyStrings = true).
  • [NotNull] (PineGuard) — rejects null only; allows empty string.
  • [Null] (PineGuard) — the inverse; the value must remain null.

Pick per property. PineGuard's content attributes ([Email], [HttpsUrl], [OwaspSafe], ...) skip null/empty by default, so they compose correctly with any of these.

Other layers, same rule library

See the full documentation for the complete attribute catalog.

License

MIT © Steve McCormack

Product 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 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 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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.0-alpha.7 194 4/20/2026
0.1.0-alpha.6 80 4/20/2026
0.1.0-alpha.5 85 4/18/2026