Preconditions.NET 2.0.2

dotnet add package Preconditions.NET --version 2.0.2
NuGet\Install-Package Preconditions.NET -Version 2.0.2
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="Preconditions.NET" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Preconditions.NET --version 2.0.2
#r "nuget: Preconditions.NET, 2.0.2"
#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 Preconditions.NET as a Cake Addin
#addin nuget:?package=Preconditions.NET&version=2.0.2

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

Preconditions.NET AppVeyor build status NuGet

<img align="right" width="128px" height="128px" src="https://raw.githubusercontent.com/lecaillon/Preconditions/master/logo128.png">

Preconditions.NET is a personal, free-time project with no funding. If you use Evolve in your daily work and feel that it makes your life easier, consider supporting its development via GitHub Sponsors ❤️ and by adding a star to this repository ⭐

Introduction

Preconditions.NET provides convenience static methods to help check that a method or a constructor is invoked with proper parameter or not. In other words it checks the pre-conditions. The goal of this class is to improve readability of code.

Preconditions.NET returns the tested value on success, allowing to check and call a method at the same time.

On failure it always throws an ArgumentException, ArgumentNullException or ArgumentOutOfRangeException.

Why Preconditions.NET v2 ?

Preconditions.NET v2.0.0 is a complete rewrite that takes advantage of nullable types, the NotNull attribute and the new .NET 6 CallerArgumentExpression attribute. It is no more mandatory to pass the parameter name being checked.

It also adds new methods (cf. checklist) and remove Check.Zero().

How to use it ?

Because Preconditions.NET is only one code file, you can either copy the Check.cs class or include the NuGet package to your project :

PM> Install-Package Preconditions.NET

Example

public class Employee : Person
{
    public Employee(string name, string id) : base(Check.NotNullOrEmpty(name))
    {
        Id = Check.NullableButNotEmpty(id);
    }

    public string Id { get; }
}

The checklist

  • Check.NotNull(object)
  • Check.NullableButNotEmpty (string)
  • Check.NotNullOrEmpty(string)
  • Check.NotNullOrEmpty(IEnumerable)
  • Check.HasNoNulls(IEnumerable)
  • Check.NotEmpty(Guid)
  • Check.FileExists()
  • Check.DirectoryExists()
  • Check.Positive()
  • Check.PositiveOrNull()
  • Check.Negative()
  • Check.NegativeOrNull()
  • Check.NotNegative()
  • Check.NotNegativeOrNull()
  • Check.True(Func<bool>)

Feedback and issues

Feedback, improvements, ideas are welcomed. Feel free to create new issues at the issues section.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • 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
2.0.2 114,741 2/16/2022
2.0.1 1,057 1/26/2022
2.0.0 726 1/4/2022
1.4.0 18,662 11/18/2017
1.3.1 100,970 10/23/2017
1.3.0 1,627 7/18/2017
1.2.1 1,452 5/17/2017
1.2.0 1,383 4/29/2017
1.1.0 1,900 3/7/2017
1.0.0 1,496 11/29/2016

## Bug fix
- NotNullOrEmpty(IEnumerable) and HasNoNulls(IEnumerable) return the same type as the one passed in parameter