![]() |
VOOZH | about |
dotnet add package Ardalis.GuardClauses --version 5.0.0
NuGet\Install-Package Ardalis.GuardClauses -Version 5.0.0
<PackageReference Include="Ardalis.GuardClauses" Version="5.0.0" />
<PackageVersion Include="Ardalis.GuardClauses" Version="5.0.0" />Directory.Packages.props
<PackageReference Include="Ardalis.GuardClauses" />Project file
paket add Ardalis.GuardClauses --version 5.0.0
#r "nuget: Ardalis.GuardClauses, 5.0.0"
#:package Ardalis.GuardClauses@5.0.0
#addin nuget:?package=Ardalis.GuardClauses&version=5.0.0Install as a Cake Addin
#tool nuget:?package=Ardalis.GuardClauses&version=5.0.0Install as a Cake Tool
<h1 align=center> <img src="media/logotype 1024.svg" width=50%> </h1>
👁 NuGet
👁 NuGet
👁 publish Ardalis.GuardClauses to nuget
<a href="https://twitter.com/intent/follow?screen_name=ardalis"> <img src="https://img.shields.io/twitter/follow/ardalis.svg?label=Follow%20@ardalis" alt="Follow @ardalis" /> </a> <a href="https://twitter.com/intent/follow?screen_name=nimblepros"> <img src="https://img.shields.io/twitter/follow/nimblepros.svg?label=Follow%20@nimblepros" alt="Follow @nimblepros" /> </a>
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.
If you like or are using this project please give it a star. Thanks!
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, dateCreated);
}
}
NotFoundException)To extend your own guards, you can do the following:
// Using the same namespace will make sure your code picks up your
// extensions no matter where they are in your codebase.
namespace Ardalis.GuardClauses
{
public static class FooGuard
{
public static void Foo(this IGuardClause guardClause,
string input,
[CallerArgumentExpression("input")] string? parameterName = null)
{
if (input?.ToLower() == "foo")
throw new ArgumentException("Should not have been foo!", parameterName);
}
}
}
// Usage
public void SomeMethod(string something)
{
Guard.Against.Foo(something);
Guard.Against.Foo(something, nameof(something)); // optional - provide parameter name
}
EnumOutOfRangehttps://user-images.githubusercontent.com/782127/234028498-96e206b0-9a70-4aa0-9c36-a62477ea0aa9.mp4
via Nicolas Carlo
If you require commercial support to include this library in your applications, contact NimblePros
1.3.2 to GitHub Releases in order for the package to actually be published to Nuget. Otherwise it will claim to have been successful but is lying to you.| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Ardalis.GuardClauses:
| Package | Downloads |
|---|---|
|
Een.Common
Nuget package for common helpers and enums |
|
|
Ardalis.SharedKernel
An example shared kernel project/package for use with Ardalis.CleanArchitecture template. You should probably replace this with your own package! |
|
|
Serilog.UI
Simple web UI for several Serilog sinks. |
|
|
mmx.utils
Package Description |
|
|
Serilog.UI.MsSqlServerProvider
Microsoft SQL Server data provider for Serilog UI. |
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, Masstransit, and Aspire in .Net 10.
|
|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
|
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, Masstransit, and Aspire in .Net 10.
|
|
|
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)
|
|
|
jasontaylordev/RapidBlazor
Clean Architecture Solution Template for Blazor WebAssembly .NET 7
|
|
|
MattParkerDev/sharpdbg
SharpDbg is a .NET managed code debugger supporting the Debug Adapter Protocol, implemented completely in C#/.NET
|
|
|
Lacro59/playnite-successstory-plugin
This plugin shows the game achievements in Playnite.
|
|
|
serilog-contrib/serilog-ui
Simple Serilog log viewer UI for several sinks.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0 | 12,038,109 | 9/30/2024 |
| 4.6.0 | 3,217,233 | 7/8/2024 |
| 4.5.0 | 4,025,525 | 2/26/2024 |
| 4.4.0 | 1,011,752 | 1/23/2024 |
| 4.3.0 | 819,875 | 12/23/2023 |
| 4.2.0 | 1,274,410 | 11/9/2023 |
| 4.1.2 | 19,328 | 11/9/2023 |
| 4.1.1 | 1,779,617 | 8/1/2023 |
| 4.1.0 | 21,211 | 8/1/2023 |
| 4.0.1 | 12,704,937 | 3/28/2022 |
| 4.0.0 | 1,047,514 | 1/18/2022 |
| 3.3.0 | 1,459,380 | 10/29/2021 |
| 3.2.0 | 1,862,051 | 5/14/2021 |
| 3.1.0 | 697,796 | 2/13/2021 |
| 3.0.1 | 749,624 | 10/9/2020 |
| 3.0.0 | 234,235 | 8/20/2020 |
| 2.0.0 | 112,550 | 7/22/2020 |
| 1.5.0 | 1,189,397 | 4/29/2020 |
| 1.4.2 | 147,314 | 3/16/2020 |
* 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)