Preconditions.NET
2.0.2
dotnet add package Preconditions.NET --version 2.0.2
NuGet\Install-Package Preconditions.NET -Version 2.0.2
<PackageReference Include="Preconditions.NET" Version="2.0.2" />
paket add Preconditions.NET --version 2.0.2
#r "nuget: Preconditions.NET, 2.0.2"
// 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
<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 | Versions 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. |
-
.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.
## Bug fix
- NotNullOrEmpty(IEnumerable) and HasNoNulls(IEnumerable) return the same type as the one passed in parameter