Ardalis.GuardClauses 6.0.0

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

Ardalis.GuardClauses

IMPORTANT This is the last MIT-licensed release of this library. Future releases will require a (potentially free) commercial license. Find out more

A simple extensible package with guard clause extensions.

A guard clause is a software pattern that simplifies complex functions by "failing fast", checking for invalid inputs up front and immediately failing if any are found.

Release Notes

This is the last MIT-licensed release of this library (see above).

  • Updated to latest supported .NET frameworks (.NET 10, .NET 11) with continued NetStandard2.0 support (#419)
    • Breaking: dropped the net8.0 and netstandard2.1 targets (.NET 8 and 9 are out of support). Projects that can't use .NET 10+ get the netstandard2.0 build instead.
  • Fixed Guard.Against.Expression so it works with reference types; the struct constraint was removed (#339, #406)
  • Fixed Guard.Against.LengthOutOfRange so the exception keeps the parameter name and your custom message (#422)
  • Updated Microsoft.SourceLink.GitHub to 10.0.400 (#410)
  • Package license is now declared as an MIT license expression, so it shows up on nuget.org and in license-scanning tools (#359)
  • NuGet package now ships its own focused readme

Usage

public void ProcessOrder(Order order)
{
    Guard.Against.Null(order);

    // process order here
}

// OR

public class Order
{
    private string _name;
    private int _quantity;
    private long _max;
    private decimal _unitPrice;
    private DateTime _dateCreated;

    public Order(string name, int quantity, long max, decimal unitPrice, DateTime dateCreated)
    {
        _name = Guard.Against.NullOrWhiteSpace(name);
        _quantity = Guard.Against.NegativeOrZero(quantity);
        _max = Guard.Against.Zero(max);
        _unitPrice = Guard.Against.Negative(unitPrice);
        _dateCreated = Guard.Against.OutOfSQLDateRange(dateCreated);
    }
}

Roadmap

This is our roadmap for this package:

Version 6.x

This version. The last MIT-licensed package.

Version 15.x

The next version. It will have minimal changes from 6.x but will have a dual license and a compile-time license check and any planned breaking changes will be marked [Obsolete] if possible to signal what's coming. It will also be released both as Ardalis.GuardClauses and as NimbleTools.GuardClauses but with identical behavior to make upgrades as easy as possible, both now and in the future.

Why the jump from 6 to 15? We want to consolidate the 3 Ardalis packages that are moving to commercial licensing (GuardClauses, SmartEnum, Specification) and, like Aspire, we want to keep our version numbers separated from .NET's version numbers. Starting at 15 for all 3 lets us do that.

Version 16.x

This is where we expect to introduce potentially breaking changes as we rethink, refactor, and improve the implementation of the library. We will not break the API without a good reason, but there are some inconsistencies and places where we can improve the usability and sometimes the performance and this will be the time to make such changes.

Stay informed of changes by adding your email here: https://nimbletools.io/updates

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 was computed.  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 is compatible.  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.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.0

    • No dependencies.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (288)

Showing the top 5 NuGet packages that depend on Ardalis.GuardClauses:

Package Downloads
Ardalis.SharedKernel

An example shared kernel project/package for use with Ardalis.CleanArchitecture template. You should probably replace this with your own package!

Een.Common

Nuget package for common helpers and enums

Serilog.UI

Simple web UI for several Serilog sinks.

mmx.utils

Package Description

Serilog.UI.MsSqlServerProvider

Microsoft SQL Server data provider for Serilog UI.

GitHub repositories (38)

Showing the top 20 popular GitHub repositories that depend on Ardalis.GuardClauses:

Repository Stars
jasontaylordev/CleanArchitecture
Clean Architecture Solution Template for ASP.NET Core
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 10
dotnet-architecture/eShopOnWeb
Sample ASP.NET Core 8.0 reference application, now community supported: https://github.com/NimblePros/eShopOnWeb
rnwood/smtp4dev
smtp4dev - the fake smtp email server for development and testing
MattParkerDev/SharpIDE
A modern, cross platform IDE for .NET, built with .NET & Godot
ardalis/SmartEnum
A base class for quickly and easily creating strongly typed enum replacements in C#.
meysamhadeli/booking-microservices
A practical microservices with the latest technologies and architectures like Vertical Slice Architecture, Event Sourcing, CQRS, DDD, gRpc, MongoDB, RabbitMq, Wolverine, and Aspire in .Net 10.
CodeMazeBlog/CodeMazeGuides
Source code for 800+ C# and .NET articles from code-maze.com. Every article is a runnable solution, most with tests.
ardalis/ddd-guestbook
A DDD guestbook example written for ASP.NET Core
ardalis/CleanArchitecture.WorkerService
A solution template using Clean Architecture for building a .NET Core Worker Service.
flyingpie/windows-terminal-quake
Enable Quake-style dropdown for (almost) any application.
NimbleSense/Susalem
加入带锅宫酱,来到苏州耶路撒冷的怀抱吧!
NimblePros/eShopOnWeb
Sample ASP.NET Core 10.0 reference application, powered by Microsoft, demonstrating a domain-centric application architecture with monolithic deployment model.
meysamhadeli/booking-modular-monolith
A practical Modular Monolith architecture with the latest technologies and architecture like Vertical Slice Architecture, Event Driven Architecture, CQRS, DDD, gRpc, Wolverine, and Aspire in .Net 10.
evangelosvlachos96-dotcom/booking-microservices
Flight booking system built as .NET 10 microservices with Vertical Slice Architecture, DDD, CQRS, Event Sourcing, gRPC, RabbitMQ, Wolverine, PostgreSQL, MongoDB and .NET Aspire.
mehdihadeli/food-delivery-modular-monolith
🌭 A practical and imaginary food and grocery delivery modular monolith, built with .Net 8, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
JasonBock/Rocks
A mocking library based on the Compiler APIs (Roslyn + Mocks)
kaybi-gh/K7
Self-hosted media server for a small circle of family and friends.
MattParkerDev/sharpdbg
SharpDbg is a .NET managed code debugger supporting the Debug Adapter Protocol, implemented completely in C#/.NET
jasontaylordev/RapidBlazor
Clean Architecture Solution Template for Blazor WebAssembly .NET 7
Version Downloads Last Updated
6.0.0 13 11/24/2026
5.0.0 18,590,662 9/30/2024
4.6.0 3,837,767 7/8/2024
4.5.0 4,466,948 2/26/2024
4.4.0 1,145,768 1/23/2024
4.3.0 887,676 12/23/2023
4.2.0 1,461,465 11/9/2023
4.1.2 19,777 11/9/2023
4.1.1 1,952,417 8/1/2023
4.1.0 21,841 8/1/2023
4.0.1 13,409,603 3/28/2022
4.0.0 1,083,947 1/18/2022
3.3.0 1,502,875 10/29/2021
3.2.0 1,961,934 5/14/2021
3.1.0 720,647 2/13/2021
3.0.1 778,381 10/9/2020
3.0.0 239,355 8/20/2020
2.0.0 114,847 7/22/2020
1.5.0 1,256,143 4/29/2020
Loading failed

* Version 6.0.0: This is the last MIT-licensed release of this library. Future releases will require a (potentially free) commercial license. See https://nimbletools.io/news/ardalis-nuget-packages/
           * Updated target frameworks to net11.0, net10.0, and netstandard2.0; dropped net8.0 and netstandard2.1, which are no longer supported (#419)
           * Fixed Guard.Against.Expression to support reference types by removing the struct constraint (#339, #406)
           * Fixed Guard.Against.LengthOutOfRange so the exception keeps the parameter name and custom message (#422)
           * Updated Microsoft.SourceLink.GitHub to 10.0.400 (#410)
           * Package license is now declared as an MIT license expression (#359)
           * NuGet package now ships a dedicated readme (readme-nuget.md)
           * Updating to 5.0 because 4.6 had breaking logic (see #354)
           * Updated Obsolete message for Guard.Against.Expression to clarify reversal of logic (#457)