Oakrey.Guards
4.0.0
dotnet add package Oakrey.Guards --version 4.0.0
NuGet\Install-Package Oakrey.Guards -Version 4.0.0
<PackageReference Include="Oakrey.Guards" Version="4.0.0" />
<PackageVersion Include="Oakrey.Guards" Version="4.0.0" />
<PackageReference Include="Oakrey.Guards" />
paket add Oakrey.Guards --version 4.0.0
#r "nuget: Oakrey.Guards, 4.0.0"
#:package Oakrey.Guards@4.0.0
#addin nuget:?package=Oakrey.Guards&version=4.0.0
#tool nuget:?package=Oakrey.Guards&version=4.0.0
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
GeneralGuardsvalidates common values such asnull,default, equality and type.NumberGuardsvalidates numeric values, signs, comparisons and ranges using generic math.StringGuardsvalidates empty/whitespace strings, length, content, equality and regex matching.SpecialGuardsvalidates 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
- Author: Oakrey
- Company: Oakrey (Website)
- License: MIT
- Repository: Common
- NuGet: Oakrey.Guards
| Product | Versions 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. |
-
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.