Ninjanaut.Preconditions 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Ninjanaut.Preconditions --version 1.0.0
NuGet\Install-Package Ninjanaut.Preconditions -Version 1.0.0
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="Ninjanaut.Preconditions" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ninjanaut.Preconditions --version 1.0.0
#r "nuget: Ninjanaut.Preconditions, 1.0.0"
#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 Ninjanaut.Preconditions as a Cake Addin
#addin nuget:?package=Ninjanaut.Preconditions&version=1.0.0

// Install Ninjanaut.Preconditions as a Cake Tool
#tool nuget:?package=Ninjanaut.Preconditions&version=1.0.0

Welcome to the Preconditions project website! Preconditions is simple and lightweight C# library to ease arguments checks.


from nuget package manager console

PM> Install-Package Ninjanaut.Preconditions

from command line

> dotnet add package Ninjanaut.Preconditions


using Ninjanaut.Preconditions;

Check.NotNull(parameter, nameof(parameter));
Check.NotNull(parameter, nameof(parameter), "Parameter cannot be null.");

Check.NotNullOrEmpty(parameter, nameof(parameter));
Check.NotNullOrEmpty(parameter, nameof(parameter), "Parameter cannot be null or empty.");

Check.Require(x > 0);
Check.Require(x > 0, "Parameter x has to be greater than zero!");
Check.Require(x > 0, "Parameter x has to be greater than zero!", nameof(x));

// It's also possible to assign the value directly from the checks.
var foo = Check.NotNull(parameter);
string bar = Check.NotNullOrEmpty(parameter);

Adding your custom checks

C# does not allow to create an extension method to static class or to create partial class across assemblies. Therefore you can create your own static class as in the following example

public static class MyCheck
	public static void NotZero(int number, string message = null, string paramName = null)
        if (number == 0)
            throw new ArgumentException(message, paramName);

and use it together with other checks



If you would like to contribute to the project, please send a pull request to the dev branch.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.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.2 396 9/5/2021
1.1.1 302 8/31/2021
1.1.0 286 8/30/2021
1.0.0 308 8/20/2021

Initial release