/PowerUtils.GuardClauses.Validations

Helpers, extensions and utilities to work with guard clauses

Primary LanguageC#MIT LicenseMIT

PowerUtils.GuardClauses.Validations

⚠️ DEPRECATED

This package has been discontinued because it never evolved, and the code present in this package does not justify its continuation. It is preferable to implement this code directly in the project if necessary or if you prefer, you can use a good projects like Ardalis.GuardClauses and Throw The package will be completely removed after 2024/02/03.

Logo

Helpers, extensions and utilities to work with guard clauses

License: MIT

Support to

  • .NET 7.0
  • .NET 6.0
  • .NET 5.0
  • .NET 3.1

Dependencies

  • PowerUtils.Net.Primitives NuGet
  • PowerUtils.Validations.Primitives NuGet

How to use

Install NuGet package

This package is available through Nuget Packages: https://www.nuget.org/packages/PowerUtils.GuardClauses.Validations

Nuget

Install-Package PowerUtils.GuardClauses.Validations

.NET CLI

dotnet add package PowerUtils.GuardClauses.Validations

Exceptions

  • BadRequestException (400):
    • BadRequestException.Factory.Create(property, errorCode);
    • BadRequestException.Factory.CreateInvalid(property);
    • BadRequestException.Factory.CreateRequired(property);
    • BadRequestException.Throw(property, errorCode);
    • BadRequestException.ThrowInvalid(property);
    • BadRequestException.ThrowRequired(property);
  • PropertyException (400):
    • PropertyException.Factory.Create(property, errorCode);
    • PropertyException.Factory.CreateInvalid(property);
    • PropertyException.Throw(property, errorCode);
    • PropertyException.ThrowInvalid(property);
  • UnauthorizedException (401):
    • UnauthorizedException.Factory.Create(property);
    • UnauthorizedException.Factory.Create(property, errorCode);
    • UnauthorizedException.Throw(property);
    • UnauthorizedException.Throw(property, errorCode);
  • ForbiddenException (403):
    • ForbiddenException.Factory.Create(property);
    • ForbiddenException.Factory.Create(property, errorCode);
    • ForbiddenException.Throw(property);
    • ForbiddenException.Throw(property, errorCode);
  • NotFoundException (404):
    • NotFoundException.Factory.Create(property);
    • NotFoundException.Factory.Create(property, errorCode);
    • NotFoundException.Throw(property);
    • NotFoundException.Throw(property, errorCode);
  • ConflictException (409):
    • ConflictException.Factory.Create(property);
    • ConflictException.Factory.Create(property, errorCode);
    • ConflictException.Throw(property);
    • ConflictException.Throw(property, errorCode);

Guard clauses

  • string:
    • Guard.Validate.IfNull();
    • Guard.Validate.IfEmpty();
    • Guard.Validate.IfNullOrEmpty();
    • Guard.Validate.IfNullOrWhiteSpace();
    • Guard.Validate.IfLongerThan();
    • Guard.Validate.IfShorterThan();
    • Guard.Validate.IfLengthOutOfRange();
    • Guard.Validate.IfLengthEquals();
    • Guard.Validate.IfLengthDifferent();
    • Guard.Validate.IfEquals();
    • Guard.Validate.IfDifferent();
    • Guard.Validate.IfNotEmail();
  • short, ushort, int, uint, long, ulong, float, double, decimal:
    • Guard.Validate.IfGreaterThan();
    • Guard.Validate.IfLessThan();
    • Guard.Validate.IfEquals();
    • Guard.Validate.IfDifferent();
    • Guard.Validate.IfOutOfRange();
  • DateTime:
    • Guard.Validate.IfGreaterThan();
    • Guard.Validate.IfGreaterThanUtcNow();
    • Guard.Validate.IfLessThan();
    • Guard.Validate.IfLessThanUtcNow();
    • Guard.Validate.IfEquals();
    • Guard.Validate.IfDifferent();
    • Guard.Validate.IfOutOfRange();
  • Guid:
    • Guard.Validate.IfEmpty();
    • Guard.Validate.IfEquals();
    • Guard.Validate.IfDifferent();
  • object:
    • Guard.Validate.IfNull();
  • IEnumerable:
    • Guard.Validate.IfNull();
    • Guard.Validate.IfEmpty();
    • Guard.Validate.IfNullOrEmpty();
    • Guard.Validate.IfCountGreaterThan();
    • Guard.Validate.IfCountLessThan();
  • Geolocation (float, double, decimal)
    • Guard.Validate.IfLatitudeOutOfRange();
    • Guard.Validate.IfLongitudeOutOfRange();

Credits

Ardalis.GuardClauses and Throw - They are excellent libraries used as inspiration to develop this library.