Guard alternatives and similar packages
Based on the "Misc" category.
Alternatively, view Guard alternatives based on common mentions on social networks and blogs.
-
Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+. -
Humanizer
Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities -
Coravel
Near-zero config .NET library that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze! -
Hashids.net
A small .NET package to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user. -
Scientist.NET
A .NET library for carefully refactoring critical paths. It's a port of GitHub's Ruby Scientist library -
WorkflowEngine
WorkflowEngine.NET - component that adds workflow in your application. It can be fully integrated into your application, or be in the form of a specific service (such as a web service). -
HidLibrary
This library enables you to enumerate and communicate with Hid compatible USB devices in .NET. -
DeviceId
A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer. -
Warden
Define "health checks" for your applications, resources and infrastructure. Keep your Warden on the watch. -
Aeron.NET
Efficient reliable UDP unicast, UDP multicast, and IPC message transport - .NET port of Aeron -
ByteSize
ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time. -
DeviceDetector.NET
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model. -
Mediator.Net
A simple mediator for .Net for sending command, publishing event and request response with pipelines supported -
https://github.com/minhhungit/ConsoleTableExt
A fluent library to print out a nicely formatted table in a console application C# -
Valit
Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead! -
FormHelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation) -
SolidSoils4Arduino
C# .NET - Arduino library supporting simultaneous serial ASCII, Firmata and I2C communication -
Validot
Validot is a performance-first, compact library for advanced model validation. Using a simple declarative fluent interface, it efficiently handles classes, structs, nested members, collections, nullables, plus any relation or combination of them. It also supports translations, custom logic extensions with tests, and DI containers. -
Outcome.NET
Never write a result wrapper again! Outcome.NET is a simple, powerful helper for methods that return a value, but sometimes also need to return validation messages, warnings, or a success bit. -
NaturalSort.Extension
๐ Extension method for StringComparison that adds support for natural sorting (e.g. "abc1", "abc2", "abc10" instead of "abc1", "abc10", "abc2"). -
SystemTextJson.JsonDiffPatch
High-performance, low-allocating JSON object diff and patch extension for System.Text.Json. Support generating patch document in RFC 6902 JSON Patch format. -
dotnet-exec
Simplified C#, dotnet execute with custom entry point, another dotnet run without project file -
trybot
A transient fault handling framework including such resiliency solutions as Retry, Timeout, Fallback, Rate Limit and Circuit Breaker.
SaaSHub - Software Alternatives and Reviews
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Guard or a related project?
Popular Comparisons
README
Guard
[Logo](media/guard-64.png)
Guard is a fluent argument validation library that is intuitive, fast and extensible.
$ dotnet add package Dawn.Guard
/ PM> Install-Package Dawn.Guard
- Introduction
- What's Wrong with Vanilla?
- Requirements
- Standard Validations
- Design Decisions
- Extensibility
- Code Snippets
Introduction
Here is a sample constructor that validates its arguments without Guard:
public Person(string name, int age)
{
if (name == null)
throw new ArgumentNullException(nameof(name), "Name cannot be null.");
if (name.Length == 0)
throw new ArgumentException("Name cannot be empty.", nameof(name));
if (age < 0)
throw new ArgumentOutOfRangeException(nameof(age), age, "Age cannot be negative.");
Name = name;
Age = age;
}
And this is how we write the same constructor with Guard:
using Dawn; // Bring Guard into scope.
public Person(string name, int age)
{
Name = Guard.Argument(name, nameof(name)).NotNull().NotEmpty();
Age = Guard.Argument(age, nameof(age)).NotNegative();
}
If this looks like too much allocations to you, fear not. The arguments are read-only structs that are passed by reference. See the design decisions for details and an introduction to Guard's more advanced features.
What's Wrong with Vanilla?
There is nothing wrong with writing your own checks but when you have lots of types you need to validate, the task gets very tedious, very quickly.
Let's analyze the string validation in the example without Guard:
- We have an argument (name) that we need to be a non-null, non-empty string.
- We check if it's null and throw an
ArgumentNullException
if it is. - We then check if it's empty and throw an
ArgumentException
if it is. - We specify the same parameter name for each validation.
- We write an error message for each validation.
ArgumentNullException
accepts the parameter name as its first argument and error message as its second while it's the other way around for theArgumentException
. An inconsistency that many of us sometimes find it hard to remember.
In reality, all we need to express should be the first bullet, that we want our argument non-null and non-empty.
With Guard, if you want to guard an argument against null, you just write NotNull
and that's it.
If the argument is passed null, you'll get an ArgumentNullException
thrown with the correct
parameter name and a clear error message out of the box. The standard validations
have fully documented, meaningful defaults that get out of your way and let you focus on your project.
Requirements
C# 7.2 or later is required. Guard takes advantage of almost all the new features introduced in
C# 7.2. So in order to use Guard, you need to make sure your Visual Studio is up to date and you
have <LangVersion>7.2</LangVersion>
or later added in your .csproj file.
.NET Standard 1.0 and above are supported. Microsoft Docs lists the following platform versions as .NET Standard 1.0 compliant but keep in mind that currently, the unit tests are only targeting .NET Core 3.0.
Platform | Version |
---|---|
.NET Core | 1.0 |
.NET Framework | 4.5 |
Mono | 4.6 |
Xamarin.iOS | 10.0 |
Xamarin.Mac | 3.0 |
Xamarin.Android | 7.0 |
Universal Windows Platform | 10.0 |
Windows | 8.0 |
Windows Phone | 8.1 |
Windows Phone Silverlight | 8.0 |
Unity | 2018.1 |
More
The default branch (dev) is the development branch, so it may contain changes/features that are not published to NuGet yet. See the master branch for the latest published version.
Standard Validations
[Click here][3] for a list of the validations that are included in the library.
Design Decisions
[Click here][1] for the document that explains the motives behind the Guard's API design and more advanced features.
Extensibility
[Click here][4] to see how to add custom validations to Guard by writing simple extension methods.
Code Snippets
Code snippets can be found in the [snippets][5] folder. Currently, only the Visual Studio is supported.