GuardClauses 2.1.0

dotnet add package GuardClauses --version 2.1.0
                    
NuGet\Install-Package GuardClauses -Version 2.1.0
                    
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="GuardClauses" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GuardClauses" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GuardClauses" />
                    
Project file
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 GuardClauses --version 2.1.0
                    
#r "nuget: GuardClauses, 2.1.0"
                    
#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 GuardClauses@2.1.0
                    
#: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=GuardClauses&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GuardClauses&version=2.1.0
                    
Install as a Cake Tool

GuardClauses

GuardClause is a check of integrity preconditions used to avoid errors during execution

Get a star

If you like the library, please give a star.

Usage

public void Execution(string name, int age)
{
  Name =  GuardClause.IsZeroOrNegative(age,nameof(age));
  Age  =  GuardClause.IsNullOrEmptyStringOrWhiteSpace(name, nameof(name));
}

Available methods

GuardClause.IsZeroOrNegative(int argumentValue, string argumentName);
GuardClause.IsZeroOrNegative(decimal argumentValue, string argumentName);
GuardClause.IsZeroOrNegative(float argumentValue, string argumentName);
GuardClause.IsZeroOrNegative(long argumentValue, string argumentName);
GuardClause.IsZeroOrNegative(double argumentValue, string argumentName);
GuardClause.IsLengthExceeded(string argumentValue, string agrumentName, int maximumLength);
GuardClause.IsNullOrEmptyStringOrWhiteSpace(string argumentValue, string argumentName);
GuardClauseEnsureValidString(string argumentValue, string argumentName,List<StringValidationType> types);
GuardClauseEnsureValidString(string argumentValue, string argumentName,StringValidationType type);
GuardClause.IsNullOrEmptyString(string argumentValue, string argumentName);
GuardClause.ArgumentIsNotNull(object value, string argumentName);
GuardClause.IsZero(int argumentValue, string argumentName);
GuardClause.IsZero(long argumentValue, string argumentName);
GuardClause.IsZero(long argumentValue, string argumentName);
GuardClause.IsZero(decimal argumentValue, string argumentName);
GuardClause.IsZero(double argumentValue, string argumentName);
GuardClause.IsZero(float argumentValue, string argumentName);
GuardClause.IsNegative(int argumentValue, string argumentName);
GuardClause.IsNegative(long argumentValue, string argumentName);
GuardClause.IsNegative(long argumentValue, string argumentName);
GuardClause.IsNegative(decimal argumentValue, string argumentName);
GuardClause.IsNegative(double argumentValue, string argumentName);
GuardClause.IsNegative(float argumentValue, string argumentName);
GuardClause.DateTimeIsGraterThan(DateTime argumentValue, string argumentName ,DateTime comparableDateTme);
GuardClause.DateTimeIsLessThan(DateTime argumentValue, string argumentName ,DateTime comparableDateTme);
GuardClause.DateTimeIsOutOfRange(DateTime argumentValue,DateTime startDateTime, string argumentName ,DateTime endDateTime);
GuardClause.IsStringEmptyGuid(string argumentValue, string argumentName);
GuardClause.IsEmptyGuid(Guid argumentValue, string argumentName);
GuardClause.IsEmailValid(string email);
GuardClause.UrlChecker(string url);
GuardClause.MaximumLength(string argumentValue, string argumentName, int maximumLength);

Nuget

https://www.nuget.org/packages/GuardClauses/

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on GuardClauses:

Package Downloads
BytLabs.Domain

DDD building blocks: entities, aggregate roots, value objects, domain events, business rules, audit and soft-delete.

BytLabs.DataAccess

Provider-agnostic unit-of-work, command transactions, and domain-event dispatch for BytLabs repositories.

BytLabs.DataAccess.EntityFramework

Entity Framework Core repository and unit-of-work for BytLabs, with per-tenant DbContext resolution.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on GuardClauses:

Repository Stars
CodeMazeBlog/CodeMazeGuides
Source code for 800+ C# and .NET articles from code-maze.com. Every article is a runnable solution, most with tests.
Version Downloads Last Updated
2.1.0 5,170 2/5/2025
2.0.0 172 2/5/2025
1.2.4 166,475 12/7/2021
1.2.3 430 12/7/2021
1.2.2 474 11/19/2021
1.2.1 463 11/16/2021
1.2.0 471 11/15/2021
1.0.0 44,969 11/10/2021