This project is inspired by Google Guava Preconditions.
Preconditions provide convenience static methods that help to 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 returns the tested value on success allowing to check and call a method at the same time.
On failure its methods always throw an ArgumentException.
Because Preconditions is only one code file, you can either copy paste the Check.cs class or include the Nuget package to your project : https://www.nuget.org/packages/Preconditions.NET
PM> Install-Package Preconditions.NET
A signed version is also available: https://www.nuget.org/packages/Preconditions.NET.StrongName
PM> Install-Package Preconditions.NET.StrongName
public class Employee : Person
{
public string Id { get; }
public Employee(string name, string id) : base(Check.NotNullOrEmpty(name, nameof(name)))
{
Id = Check.NullableButNotEmpty(id, nameof(id));
}
}- Check.NotNullOrEmpty(string)
- Check.NullableButNotEmpty (string)
- Check.NotNull(object)
- Check.NotEmpty(IEnumerable)
- Check.HasNoNulls(IEnumerable)
- Check.FileExists()
- Check.DirectoryExists()
- Check.Negative()
- Check.Zero()
- Check.Positive()
Feedback, improvements, ideas are welcomed. Feel free to create new issues at the issues section.