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
<PackageReference Include="Atya.Foundation.Guards" Version="1.0.2" />
<PackageVersion Include="Atya.Foundation.Guards" Version="1.0.2" />
<PackageReference Include="Atya.Foundation.Guards" />
paket add Atya.Foundation.Guards --version 1.0.2
#r "nuget: Atya.Foundation.Guards, 1.0.2"
#:package Atya.Foundation.Guards@1.0.2
#addin nuget:?package=Atya.Foundation.Guards&version=1.0.2
#tool nuget:?package=Atya.Foundation.Guards&version=1.0.2
Atya.Foundation.Guards
Lightweight guard clauses for validating arguments and protecting invariants in modern .NET code.
๐ 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 | 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 (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 |