Atya.Foundation.Guards 1.0.2

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

Atya.Foundation.Guards

Lightweight guard clauses for validating arguments and protecting invariants in modern .NET code.

NuGet Version Downloads .NET 10.0 License: MIT

๐Ÿ“– Overview

Atya.Foundation.Guards provides a compact set of guard clauses for validating method arguments, constructor parameters, and low-level invariants. It helps fail fast with standard .NET exceptions while preserving the original argument name through caller argument expressions. The package is intended for foundation libraries and application code that need clear validation without a large dependency surface.

โœจ Features

  • Null validation โ€” validate reference types and nullable value types with ArgumentNullException.
  • String guards โ€” reject null, empty, and whitespace-only strings.
  • Collection guards โ€” validate read-only collections and enumerables without unnecessary enumeration when counts are available.
  • Numeric guards โ€” enforce inclusive ranges, non-negative values, and values greater than zero.
  • Invariant-friendly API โ€” return the validated value so guards can be used directly in assignments.

๐Ÿ“ฆ Installation

.NET CLI

dotnet add package Atya.Foundation.Guards

Package Manager

Install-Package Atya.Foundation.Guards

PackageReference

<PackageReference Include="Atya.Foundation.Guards" Version="1.0.0" />

๐Ÿš€ Quick Start

using Atya.Foundation.Guards;
using System;

string customerName = Guard.AgainstNullOrWhiteSpace("Ada Lovelace");
int quantity = Guard.AgainstZeroOrNegative(25);
Guid customerId = Guard.AgainstEmpty(Guid.NewGuid());

Console.WriteLine($"{customerName}: {customerId} ({quantity})");

๐Ÿ“š Usage

Validate Constructor Input

using Atya.Foundation.Guards;
using System;

public sealed class OrderRequest(Guid customerId, string customerName, int quantity)
{
    public Guid CustomerId { get; } = Guard.AgainstEmpty(customerId);

    public string CustomerName { get; } = Guard.AgainstNullOrWhiteSpace(customerName);

    public int Quantity { get; } = Guard.AgainstZeroOrNegative(quantity);
}

Validate Ranges

using Atya.Foundation.Guards;

int retryCount = Guard.AgainstOutOfRange(3, minimum: 1, maximum: 10);
decimal discount = Guard.AgainstNegative(0.15m);

Validate Collections

using Atya.Foundation.Guards;
using System;
using System.Collections.Generic;
using System.Linq;

IReadOnlyCollection<Guid> candidateItemIds = new List<Guid> { Guid.NewGuid(), Guid.NewGuid() };
IReadOnlyCollection<Guid> itemIds = Guard.AgainstNullOrEmpty(candidateItemIds);

IEnumerable<int> candidatePageNumbers = Enumerable.Range(1, 3);
IEnumerable<int> pageNumbers = Guard.AgainstNullOrEmpty(candidatePageNumbers);

๐Ÿงฉ API Overview

Type Description
Guard Static entry point for all guard clauses.
Guard.AgainstNull Validates reference types and nullable value types.
Guard.AgainstNullOrEmpty Validates strings, read-only collections, and enumerables.
Guard.AgainstNullOrWhiteSpace Validates strings that must contain non-whitespace text.
Guard.AgainstDefault Rejects the default value for value types.
Guard.AgainstEmpty Rejects Guid.Empty.
Guard.AgainstOutOfRange Validates int, long, and decimal values against an inclusive range.
Guard.AgainstNegative Rejects negative int, long, and decimal values.
Guard.AgainstZeroOrNegative Rejects zero or negative int, long, and decimal values.

๐Ÿ—‚๏ธ Project Structure

๐Ÿ“ฆ Guards
โ”œโ”€โ”€ ๐Ÿ“‚ src
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Guards.csproj                  # the published package
โ”œโ”€โ”€ ๐Ÿงช tests
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Guards.UnitTests.csproj
โ”œโ”€โ”€ ๐ŸŽฏ samples
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Guards.Samples.Console.csproj
โ”œโ”€โ”€ โšก benchmarks
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Guards.Benchmarks.csproj
โ”œโ”€โ”€ โš™๏ธ .github/workflows
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ ci.yml
โ”œโ”€โ”€ ๐Ÿ“„ Guards.sln
โ”œโ”€โ”€ ๐Ÿ“„ README.md
โ””โ”€โ”€ ๐Ÿ“„ LICENSE
Icon Meaning
๐Ÿ“ฆ Solution / repo root (.sln)
๐Ÿ“‚ src Library source code (the published package)
๐Ÿงช tests Unit & integration tests
๐ŸŽฏ samples / examples Runnable usage samples
โšก benchmarks Performance benchmarks
๐Ÿ“š docs Documentation
โš™๏ธ .github CI/CD & repo config
๐Ÿ“„ Notable single file

๐ŸŽฏ Compatibility

Targets net10.0. The package is platform-neutral and uses standard .NET exception types.

๐Ÿงช Testing

dotnet test

โšก Benchmarks

Benchmarks are available under benchmarks/Guards.Benchmarks and can be run in Release configuration.

dotnet run --project benchmarks/Guards.Benchmarks/Guards.Benchmarks.csproj --configuration Release

๐Ÿค Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

๐Ÿ“„ License

Released under the MIT license. See LICENSE for details.


๐Ÿ›๏ธ About Atya Libraries

Atya.Foundation.Guards is part of Atya Libraries โ€” a family of focused, modern .NET libraries published under the reserved Atya.* prefix on NuGet. Every package shares the same principles: a small, clear public API, full test coverage, and consistent documentation.

๐Ÿ”Ž Browse the full collection on GitHub and NuGet.

Made with ๐Ÿ’œ .NET ยท ยฉ 2026 Atya Libraries

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 (19)

Showing the top 5 NuGet packages that depend on Atya.Foundation.Guards:

Package Downloads
Atya.Diagnostics.Logging

Logging abstractions and dependency injection helpers for Atya diagnostics packages.

Atya.Diagnostics.Metrics

Metrics abstractions and dependency injection helpers for Atya diagnostics packages.

Atya.Diagnostics.Tracing

Provider-agnostic tracing helpers for .NET applications built on System.Diagnostics.Activity.

Atya.Errors.Exceptions

Reusable exception taxonomy for modern .NET applications.

Atya.Diagnostics.Observation

Thin diagnostics composition package over logging, tracing, and metrics.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 907 7/2/2026
1.0.1 147 7/1/2026
1.0.1-oidc.20260621.2 80 6/21/2026
1.0.1-oidc.20260621.1 83 6/21/2026
1.0.1-oidc.20260619.6 93 6/21/2026
1.0.1-oidc.20260619.5 86 6/21/2026
1.0.1-oidc.20260619.1 88 6/18/2026
1.0.0 2,550 5/2/2026