/basic-guards

C# Basic guards clauses

Primary LanguageC#

Build Nuget Package Nuget

Basic guard clauses

A collection of basic guard clauses used to validate input parameters in C#.

Supported clauses

Here is a list of the supported clauses. More clauses will be added over time. Feel free to contribute with this repository.

ThrowIfNullOrWhitespace is used to validate string values against null or whitespace values.

public SampleConstructor(string stringValue)
{
    this.StringValue = stringValue.ThrowIfNullOrWhitespace(nameof(stringValue));
}

ThrowIfNull is used to validate a T value against null.

public SampleConstructor(MyDomainModel input)
{
    this.MyDomainModel = input.ThrowIfNull(nameof(input));
}