Oakrey.Guards 4.0.0

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

Oakrey.Guards

Small guard-clause library for validating method arguments and enforcing preconditions in .NET applications.

Installation

dotnet add package Oakrey.Guards

Package Manager Console:

Install-Package Oakrey.Guards

Requirements

  • .NET 10.0 or higher
  • Nullable reference types friendly API

Usage

using Oakrey.Guards;

public void CreateUser(string email, string name, int age)
{
    email.ThrowIfEmpty(nameof(email));
    email.ThrowIfEmailIsInvalid();
    name.ThrowIfLengthOutOfRange(2, 50, nameof(name));
    age.ThrowIfNotInRange(18, 120, nameof(age));

    // Continue with validated inputs.
}

Guard Groups

  • GeneralGuards validates common values such as null, default, equality and type.
  • NumberGuards validates numeric values, signs, comparisons and ranges using generic math.
  • StringGuards validates empty/whitespace strings, length, content, equality and regex matching.
  • SpecialGuards validates email addresses, display names and culture-specific phone numbers.

Non-Throwing Validation

SpecialGuards also contains helpers for user-input flows where exceptions are not desirable as control flow:

bool emailOk = email.IsEmailValid();
bool nameOk = name.IsNameValid(2, 50);
bool phoneOk = phone.IsPhoneNumberValid(new CultureInfo("en-US"));

Security Notes

Regex-based guards use a bounded timeout to reduce the risk of catastrophic backtracking on untrusted input. Range guards validate invalid range definitions, for example when min > max, before evaluating the supplied value.

Project Information

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Oakrey.Guards:

Package Downloads
Oakrey.Xml

Provides a framework for working with XML in .NET applications, including parsing extensions, validation, XSD support, serialization, and LINQ to XML enhancements. Simplifies XML data manipulation and validation

Oakrey.Files

Package contains: Utilities for file naming and compression, including FileNameGenerator for generating unique file names, FileNameSource for dynamic file path creation, and ZipCompression for compressing and decompressing files and byte arrays.

Oakrey.Capsule.Metadata

Capsule.Metadata encodes strongly-typed key-value metadata records into the Oakrey Capsule binary framing protocol (capsule ID 0xFFFF). Each record carries a key, a DataType (String, Boolean, Byte, Short, Long, Int, Float, Double), an optional Unit, and a typed value. Up to 255 records can be batched in a single MetaCapsule. Suitable for IoT, telemetry, and data-logging scenarios.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 180 7/13/2026
3.0.1 269 5/21/2026
3.0.0 525 11/13/2025
2.0.0 253 10/30/2025
1.0.1 197 9/26/2025
1.0.0 599 4/16/2025