Tolitech.Results.Guards
1.0.0-preview.6
This is a prerelease version of Tolitech.Results.Guards.
dotnet add package Tolitech.Results.Guards --version 1.0.0-preview.6
NuGet\Install-Package Tolitech.Results.Guards -Version 1.0.0-preview.6
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="Tolitech.Results.Guards" Version="1.0.0-preview.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Results.Guards" Version="1.0.0-preview.6" />
<PackageReference Include="Tolitech.Results.Guards" />
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 Tolitech.Results.Guards --version 1.0.0-preview.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tolitech.Results.Guards, 1.0.0-preview.6"
#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 Tolitech.Results.Guards@1.0.0-preview.6
#: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=Tolitech.Results.Guards&version=1.0.0-preview.6&prerelease
#tool nuget:?package=Tolitech.Results.Guards&version=1.0.0-preview.6&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tolitech.Results.Guards
Tolitech.Results.Guards provides fluent guard clauses for parameter and state validation, integrating with the Results pattern for standardized error handling.
Features
- Fluent validation for strings, collections, numbers, dates, booleans, and generics.
- Chaining of multiple validations in a readable and expressive way.
- Direct integration with Result objects.
Usage Examples
String Validation
result.Guard(name)
.ErrorIfNullOrEmpty()
.ErrorIfLengthGreaterThan(50);
Numeric Validation
result.Guard(age)
.ErrorIfLessThan(18);
Boolean Validation
result.Guard(approved)
.ErrorIfFalse();
Guid Validation
result.Guard(id)
.ErrorIfNotEqualTo(Guid.Empty);
Collection Validation
result.Guard(list)
.ErrorIfEmpty()
.ErrorIfCountGreaterThan(100);
Date Validation
result.Guard(birthDate)
.ErrorIfFuture();
Generic Validation
result.Guard(value)
.ErrorIfNull()
.ErrorIfEqualTo(expectedValue);
Available Guards
- String:
ErrorIfNull
,ErrorIfNullOrEmpty
,ErrorIfNullOrWhiteSpace
,ErrorIfNotNull
,ErrorIfNotNullOrNotEmpty
,ErrorIfEqualTo
,ErrorIfNotEqualTo
,ErrorIfLengthEqualTo
,ErrorIfLengthNotEqualTo
,ErrorIfLengthGreaterThan
,ErrorIfLengthGreaterThanOrEqualTo
,ErrorIfLengthLessThan
,ErrorIfLengthLessThanOrEqualTo
,ErrorIfNotValidEmail
,ErrorIfContains
,ErrorIfNotContains
. - Boolean:
ErrorIfNull
,ErrorIfNotNull
,ErrorIfTrue
,ErrorIfFalse
,ErrorIfFalseOrNull
,ErrorIfTrueOrNull
,ErrorIfEqualTo
,ErrorIfNotEqualTo
. - Guid:
ErrorIfNull
,ErrorIfNotNull
,ErrorIfEqualTo
,ErrorIfNotEqualTo
,ErrorIfNullOrEmpty
,ErrorIfNotNullOrNotEmpty
. - Collections:
ErrorIfNull
,ErrorIfNotNull
,ErrorIfEmpty
,ErrorIfNotEmpty
,ErrorIfCountEqualTo
,ErrorIfCountNotEqualTo
,ErrorIfCountGreaterThan
,ErrorIfCountGreaterThanOrEqualTo
,ErrorIfCountLessThan
,ErrorIfCountLessThanOrEqualTo
. - DateTime:
ErrorIfFuture
,ErrorIfFutureUtc
,ErrorIfNotFuture
,ErrorIfNotFutureUtc
,ErrorIfPast
,ErrorIfPastUtc
,ErrorIfNotPast
,ErrorIfNotPastUtc
. - Generics:
ErrorIfNull
,ErrorIfNotNull
,ErrorIfEqualTo
,ErrorIfNotEqualTo
,ErrorIfLessThan
,ErrorIfLessThanOrEqualTo
,ErrorIfGreaterThan
,ErrorIfGreaterThanOrEqualTo
,ErrorIfBetween
,ErrorIfNotBetween
.
Complete Example
result.Guard()
.ErrorIfNullOrEmpty(email)
.ErrorIfNotValidEmail(email)
.ErrorIfLengthGreaterThan(email, 100)
.ErrorIfNull(value)
.ErrorIfLessThan(value, 10);
Advanced Tips
- Chain as many validations as needed.
- Use together with Tolitech.Results to standardize error handling.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net9.0
- Tolitech.Results (>= 1.0.0-preview.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Tolitech.Results.Guards:
Package | Downloads |
---|---|
Tolitech.Domain.Results.Guards
This library contains specific Guards to validate domain artifacts such as Entities, Aggregates, Value Objects, and EntityId. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-preview.6 | 142 | 9/19/2025 |
1.0.0-preview.5 | 158 | 8/30/2025 |
1.0.0-preview.4 | 333 | 7/25/2025 |
1.0.0-preview.3 | 125 | 7/17/2025 |
1.0.0-preview.2 | 138 | 7/1/2025 |
1.0.0-preview.1 | 112 | 12/6/2024 |