Tolitech.Results.Guards 1.0.0-alpha09

This is a prerelease version of Tolitech.Results.Guards.
dotnet add package Tolitech.Results.Guards --version 1.0.0-alpha09
NuGet\Install-Package Tolitech.Results.Guards -Version 1.0.0-alpha09
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-alpha09" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tolitech.Results.Guards --version 1.0.0-alpha09
#r "nuget: Tolitech.Results.Guards, 1.0.0-alpha09"
#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.
// Install Tolitech.Results.Guards as a Cake Addin
#addin nuget:?package=Tolitech.Results.Guards&version=1.0.0-alpha09&prerelease

// Install Tolitech.Results.Guards as a Cake Tool
#tool nuget:?package=Tolitech.Results.Guards&version=1.0.0-alpha09&prerelease

Results.Guards

Results.Guards is a utility library that provides fluent and expressive guard clauses for result-oriented programming. Simplify validation and error handling with these extension methods:

Why Use Guards?

Guards serve as robust sentinels in your code, ensuring that only valid and expected values proceed. Here's why integrating guards, such as Results.Guards, is beneficial:

  • Expressive Validation: Guards offer a clear and expressive way to validate input parameters, making your code self-documenting and easy to understand.
  • Error Prevention: By catching invalid inputs early, guards help prevent errors before they can propagate through the system, leading to more stable and reliable software.
  • Readability and Maintainability: Integrating guards improves the overall readability of your code, making it easier to maintain and reducing the cognitive load on developers.
  • Fluent API: Results.Guards provides a fluent API, allowing you to chain multiple validation checks in a concise and readable manner.
  • Result-Oriented Programming: Guards seamlessly align with a result-oriented programming paradigm, where the outcome of operations is explicitly represented, enhancing code clarity.
  • Consistent Error Handling: Guards promote consistency in error handling by providing a standardized way to raise errors when validation conditions are not met.
  • Enhanced Debugging: With guards, you can easily identify the source of issues related to invalid input, simplifying the debugging process and reducing time-to-resolution.

By incorporating guards into your codebase, you not only strengthen its integrity but also contribute to a more maintainable and developer-friendly project.

String

ErrorIfNullOrEmpty

result.Guard()
    .ErrorIfNullOrEmpty(categoryName);

ErrorIfNullOrWhiteSpace

result.Guard()
    .ErrorIfNullOrEmpty(categoryName);

ErrorIfNotNullOrNotEmpty

result.Guard()
    .ErrorIfNotNullOrNotEmpty(categoryName);

ErrorIfLengthEqualTo

result.Guard()
    .ErrorIfLengthEqualTo(text, length);

ErrorIfLengthNotEqualTo

result.Guard()
    .ErrorIfLengthNotEqualTo(text, length);

ErrorIfLengthGreaterThan

result.Guard()
    .ErrorIfLengthGreaterThan(text, length);

ErrorIfLengthGreaterThanOrEqualTo

result.Guard()
    .ErrorIfLengthGreaterThanOrEqualTo(text, length);

ErrorIfLengthLessThan

result.Guard()
    .ErrorIfLengthLessThan(text, length);

ErrorIfLengthLessThanOrEqualTo

result.Guard()
    .ErrorIfLengthLessThanOrEqualTo(text, length);

ErrorIfNotValidEmail

result.Guard()
    .ErrorIfNotValidEmail(email);

DateTime

ErrorIfFuture

result.Guard()
    .ErrorIfFuture(date);

ErrorIfFutureUtc

result.Guard()
    .ErrorIfFutureUtc(date);

ErrorIfNotFuture

result.Guard()
    .ErrorIfNotFuture(date);

ErrorIfNotFutureUtc

result.Guard()
    .ErrorIfNotFutureUtc(date);

ErrorIfPast

result.Guard()
    .ErrorIfPast(date);

ErrorIfPastUtc

result.Guard()
    .ErrorIfPastUtc(date);

ErrorIfNotPast

result.Guard()
    .ErrorIfNotPast(date);

ErrorIfNotPastUtc

result.Guard()
    .ErrorIfNotPastUtc(date);

Boolean

ErrorIfTrue

result.Guard()
    .ErrorIfTrue(approved);

ErrorIfFalse

result.Guard()
    .ErrorIfFalse(approved);

ErrorIfFalseOrNull

result.Guard()
    .ErrorIfFalseOrNull(approved);

ErrorIfTrueOrNull

result.Guard()
    .ErrorIfTrueOrNull(approved);

Collections

ErrorIfEmpty<T>

result.Guard()
    .ErrorIfEmpty(list);

ErrorIfNotEmpty<T>

result.Guard()
    .ErrorIfNotEmpty(list);

ErrorIfCountEqualTo<T>

result.Guard()
    .ErrorIfCountEqualTo(list, count);

ErrorIfCountNotEqualTo<T>

result.Guard()
    .ErrorIfCountNotEqualTo(list, count);

ErrorIfCountGreaterThan<T>

result.Guard()
    .ErrorIfCountGreaterThan(list, count);

ErrorIfCountGreaterThanOrEqualTo<T>

result.Guard()
    .ErrorIfCountGreaterThanOrEqualTo(list, count);

ErrorIfCountLessThan<T>

result.Guard()
    .ErrorIfCountLessThan(list, count);

ErrorIfCountLessThanOrEqualTo<T>

result.Guard()
    .ErrorIfCountLessThanOrEqualTo(list, count);

Generics

ErrorIfNull<T>

result.Guard()
    .ErrorIfNull(amount);

ErrorIfNotNull<T>

result.Guard()
    .ErrorIfNotNull(amount);

ErrorIfEqualTo<T>

result.Guard()
    .ErrorIfEqualTo(amount, target);

ErrorIfNotEqualTo<T>

result.Guard()
    .ErrorIfEqualTo(amount, target);

ErrorIfLessThan<T>

result.Guard()
    .ErrorIfLessThan(amount, maximum);

ErrorIfLessThanOrEqualTo<T>

result.Guard()
    .ErrorIfLessThanOrEqualTo(amount, maximum);

ErrorIfGreaterThan<T>

result.Guard()
    .ErrorIfGreaterThan(amount, minimum);

ErrorIfGreaterThanOrEqualTo<T>

result.Guard()
    .ErrorIfGreaterThanOrEqualTo(amount, minimum);

ErrorIfBetween<T>

result.Guard()
    .ErrorIfBetween(amount, minimum, maximum);

ErrorIfNotBetween<T>

result.Guard()
    .ErrorIfNotBetween(amount, minimum, maximum);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tolitech.Results.Guards:

Package Downloads
Tolitech.CleanArchitecture.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-alpha09 64 1/16/2024
1.0.0-alpha08 54 1/15/2024
1.0.0-alpha07 51 1/15/2024
1.0.0-alpha06 54 1/15/2024
1.0.0-alpha05 74 12/15/2023
1.0.0-alpha04 64 12/13/2023
1.0.0-alpha03 65 12/11/2023
1.0.0-alpha02 80 12/3/2023
1.0.0-alpha01 70 12/1/2023

Correction in generic comparison between null and non-null.