CheckValidators 1.0.14

.NET 6.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package CheckValidators --version 1.0.14
NuGet\Install-Package CheckValidators -Version 1.0.14
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="CheckValidators" Version="1.0.14" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CheckValidators --version 1.0.14
#r "nuget: CheckValidators, 1.0.14"
#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.
// Install CheckValidators as a Cake Addin
#addin nuget:?package=CheckValidators&version=1.0.14

// Install CheckValidators as a Cake Tool
#tool nuget:?package=CheckValidators&version=1.0.14

Check Validators (.NET)

Author: Ryan Kueter
Updated: Febrary, 2022


Check Validators is a free .NET library, available from the NuGet Package Manager, that provides a simple, elegant, and powerful way to validate and guard your data. It also provides the ability to write your own validation extensions.


  • .NET 6


Each "Check" contains validation rules that can be chained together using method extension syntax. The If, IfNot, ElseIf, and ElseIfNot rules allow you to use Linq to validate the different members of the class, including properties, lists, dictionaries, and other complex types. If an exception is thrown, it will aggrigate a list of errors that can be retrieved with GetErrors() or the errors can be thrown with ThrowErrors(). It also has an IsValid() method that returns true if all conditions were met and false if at least one condition failed.

using CheckValidators;

string? i = null;

var c = new Check<string?>(i)
    .IfNull("The string is null.")
    .IfEmptyOrWhitespace("The string is empty.")
    .ElseIfNot(s => s.Contains("keyword"), "The string did not contain the keyword.");

// Getting errors
if (c.HasErrors())
    foreach (var s in c.GetErrors())

// Throwing errors
if (!c.IsValid())

A Realistic Example

In this example, if the People list is null, the fourth condition will produce an error. And the following ElseIfNot statement will not execute if any previous If rule produced an error. This provides better performance, and prevents unnecessary code execution and unnecessary errors. An example may include checking a child value of a value that was previously determined to be null. If a value is null, no errors will be thrown unless the IfNull rule is applied, and IsValid() will always evaluate to false. Check statements can be used inside Check statements to validate complex items.

    new Check<MyServiceRequest>(request)
        .IfNull("The service request cannot be null.")
        .If(p => p.User == null, "The user is invalid.")
        .If(p => new Check<string>(p.Email).IfNull().IfNotEmail().HasErrors(), "The email is invalid.")
        .IfNot(p => p.People.Any(), "The request does not contain any people.")
        .ElseIf(p => p.People.Where(x => new Check<string>(x.Email).IfNull().IfNotEmail().HasErrors()).Any(), "User has an invalid email.")
        .If(p => p.TimeStamp == default, "Invalid timestamp.")
catch (Exception ex)

Errors: 1) The email is invalid., 2) User has an invalid email., 3) Invalid timestamp. (Parameter 'MyServiceRequest')

Extension Methods

You can create your own custom extension methods anywhere in your project to add custom validators that are specific to your needs. If you choose to use a try/catch block, consider throwing the same error in the catch block when using an IfNot or ElseIfNot rule since they evaluate to false. Avoid throwing the same error in a catch block of an If or ElseIf rule since they evaluate to true.

public static partial class CheckValidatorsExtensions
    public static Check<List<T>?> IfEmpty<T>(this Check<List<T>?> data, string msg = "")
        if (data.InvalidModel()) { return data; }
            if (!data.Value.Any())
                data.ThrowError(msg, "The list is empty.");
        catch { }
        return data;


If you would like to contribute to this project, please contribute on the Github project page.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.27 75 9/12/2023
1.1.26 80 9/11/2023
1.1.25 79 9/10/2023
1.1.24 90 9/9/2023
1.1.23 83 9/9/2023
1.1.22 75 9/9/2023
1.1.21 85 9/9/2023
1.1.20 79 9/9/2023
1.1.19 320 11/26/2022
1.1.18 363 9/30/2022
1.1.17 392 9/12/2022
1.1.16 364 8/15/2022
1.1.15 380 6/10/2022
1.1.14 372 6/10/2022
1.1.13 381 6/10/2022
1.1.12 378 6/7/2022
1.1.10 382 6/6/2022
1.1.9 384 6/6/2022
1.1.8 376 6/6/2022
1.1.7 363 6/6/2022
1.1.6 383 6/5/2022
1.1.5 370 6/5/2022
1.1.4 376 6/3/2022
1.1.3 385 6/3/2022
1.1.2 389 6/2/2022
1.1.0 410 6/2/2022
1.0.17 407 5/3/2022
1.0.16 407 5/2/2022
1.0.15 415 5/2/2022
1.0.14 409 2/22/2022
1.0.13 391 2/22/2022

Fixed a link in the documentation following the initial release.