Shared libraries
Guard
Null, empty, positive, and range checks at a public boundary
Four argument checks that throw BCL exceptions and return the checked value. net8.0, net9.0, and net10.0. Version 0.1.1 is in source and is not on nuget.org yet.
Install
dotnet add package NuvyntraLabs.NET.GuardPackage ID: NuvyntraLabs.NET.Guard
NuvyntraLabs.NET.* is a class library, not a Plugin.Maui.* package. The install command applies after 0.1.1 is published. Until then, reference the project in the hub submodule.
Example
object request = Guard.NotNull(request);
string name = Guard.NotEmpty(name);
decimal amount = Guard.Positive(amount);
int age = Guard.InRange(age, 18, 100);Overview
NuvyntraLabs.NET.Guard is for a public method that should reject null, empty, non-positive, or out-of-range input and then use the same value. CallerArgumentExpression names the argument. Prefer ArgumentNullException.ThrowIfNull, then Ardalis.GuardClauses, when those already match the host. There is no custom exception type and no GuardAgainst vocabulary.
Capabilities
- NotNull throws ArgumentNullException and returns the reference.
- NotEmpty throws ArgumentException for null, empty, or whitespace.
- Positive throws ArgumentOutOfRangeException when the number is not greater than zero.
- InRange throws ArgumentOutOfRangeException when the value is outside the inclusive bounds.
- No package dependencies. Nullable, trim, and Native AOT compatible. Plugins do not reference it.
- .NET
- Guard
- Arguments
Discussion
Comment on NuvyntraLabs.NET.Guard. The thread lives on this component's GitHub repository. Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.
Issues are not enabled on this repository
Open the conversation on GitHub, or use the Giscus tab if Discussions are available.