Ministry of Technology
Show Menu

Fluent Guard

Fluent Guard
Created by Ministry
Language
.net Framework 4.0+ / .net Standard 1.0 / C#
Type
Library

This project provides simple extension methods for handling argument validation in a fluent form.

Examples

Here's some examples of how it can be used...

public void MyMethod(object param1)
{
    param1.ThrowIfNull(nameof(param1));     
}

public void MyMethod(string param1)
{
    param1.ThrowIfNullOrEmpty(nameof(param1));    
}

It is fully fluent, returning the original object, allowing methods like this...

public int Increment(int? param1)
    => param1.ThrowIfNull(nameof(param1)) + 1;

Available Methods

The following fluent error checkas are available along with the exceptions they can generate (depedning on the value)…

  • ThrowIfNull - ArgumentNullException
  • ThrowIfNullOrEmpty - ArgumentNullException / ArgumentException
  • ThrowIf - ArgumentException
  • ThrowOutOfRangeIf - ArgumentOutOfRangeException
Visit us on GitHub