A set of helper functions to aid in argument validations.
The first few lines of any well behaved function should be argument validation. Fail fast, fail early is not only the motto in the startup world, but the same mantra works when writing a well groomed function. Once you set up the expectations and constraints it also narrows down the behaviour matrix that you need to test. Read more ...
Check for Null or Empty
public void AddPerson(string personId, Person personData)
{
Throw.IfNullOrEmpty(personId, nameof(personId));
Throw.IfNull(personData, nameof(personData));
Check for condition
public void Compute(int generation)
{
Throw.IfNot(() => generation > 100);
Check for range
public void Compute(int generation)
{
Throw.IfOutOfRange(generation, 1, 100, nameof(generation));
First, install NuGet. Then, install Argument.Validator from the package manager console:
Install-Package Argument.Validator
A big thanks to Olivia Ifrim who helped craft the API requirements.