Skip to content

Helper functions to aid in argument validation

License

Notifications You must be signed in to change notification settings

hh532/ArgumentValidator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

A set of helper functions to aid in argument validations.

Motivation

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 ...

Usage example

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));

Installation

First, install NuGet. Then, install Argument.Validator from the package manager console:

Install-Package Argument.Validator

Acknowledgments

A big thanks to Olivia Ifrim who helped craft the API requirements.

About

Helper functions to aid in argument validation

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C# 100.0%