/ByteDev.ArgValidation

Set of helper methods to help validate arguments.

Primary LanguageC#MIT LicenseMIT

Build status NuGet Package License: MIT

ByteDev.ArgValidation

.NET Standard library of helper methods to help validate arguments.

The library is dependent on the package ByteDev.Exceptions and uses the custom exceptions from that package where appropriate. If use of exceptions from the package is not desired I would recommend a project such as GuardClauses instead.

Installation

ByteDev.ArgValidation has been written as a .NET Standard 2.0 library, so you can consume it from a .NET Core or .NET Framework 4.6.1 (or greater) application.

ByteDev.ArgValidation is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.ArgValidation

Further details can be found on the nuget page.

Release Notes

Releases follow semantic versioning.

Full details of the release notes can be viewed on GitHub.

Usage

All argument validation can be performed through the ArgMustBe class. This class has a number of static methods:

  • Between
  • GreaterThan
  • GreaterThanOrEqual
  • In
  • LessThan
  • LessThanOrEqual
  • NotDefault
  • NotEmpty
  • NotEquals
  • NotIn
  • NotNull
  • NotNullDependency
  • NotNullOrEmpty
  • NotNullOrWhiteSpace

Example:

public Customer GetCustomer(int id)
{
	ArgMustBe.GreaterThan(id, 0, nameof(id));

	// ...
}