Joutsen v0.5.0+12-g5dd5f7e
Static Public Member Functions | List of all members
Joutsen.Precondition Class Reference

A static class that can be used to easily check input values of a method. More...

Static Public Member Functions

static TValue CheckNotNull< TValue > (TValue value, String name=null)
 Checks if a value is null and throws an System.ArgumentNullException if it is. More...
 
static TValue CheckNotNull< TValue > (TValue value, Exception exception)
 Checks if a value is null and throws the exception if it is. More...
 
static String CheckNotNullOrEmpty (String value, String name=null)
 Checks if a String value is null or an empty string and raises an System.ArgumentException if it is. More...
 
static String CheckNotNullOrEmpty (String value, Exception exception)
 Checks if a String value is null or an empty string and raises an System.ArgumentException if it is. More...
 
static String CheckNotNullOrWhiteSpace (String value, String name=null)
 Checks if a string argument is null or consists only out of invisible or white space characters. More...
 
static String CheckNotNullOrWhiteSpace (String value, Exception exception)
 Checks if a string argument is null or consists only out of invisible or white space characters. More...
 
static T CheckRange< T > (T value, T min, T max, String name=null)
 Checks if an argument value is between an upper and lower bound. More...
 
static T CheckRange< T > (T value, T min, T max, Exception exception)
 Checks if an argument value is between an upper and lower bound. More...
 
static T CheckUpperBound< T > (T value, T max, String name=null)
 Checks if an argument value is below an upper bound. More...
 
static T CheckUpperBound< T > (T value, T max, Exception exception)
 Checks if an argument value is below an upper bound. More...
 
static T CheckLowerBound< T > (T value, T min, String name=null)
 Checks if an argument value exceeds a lower bound. More...
 
static T CheckLowerBound< T > (T value, T min, Exception exception)
 Checks if an argument value exceeds a lower bound. More...
 
static T CheckType< T > (object value, String name=null)
 Checks if an argument value is of a certain type. More...
 
static T CheckType< T > (object value, Exception exception)
 Checks if an argument value is of a certain type. More...
 

Detailed Description

A static class that can be used to easily check input values of a method.

Since
0.2.1

Member Function Documentation

◆ CheckLowerBound< T >() [1/2]

static T Joutsen.Precondition.CheckLowerBound< T > ( value,
min,
Exception  exception 
)
static

Checks if an argument value exceeds a lower bound.

Parameters
valuethe argument value to check
minthe lowest value that is allowed
exceptionthe exception to throw if the value is not within the bound of @paramref max
Returns
the argument value if it is within the bound of @paramref min
Since
0.5.0
Type Constraints
T :IComparable 

◆ CheckLowerBound< T >() [2/2]

static T Joutsen.Precondition.CheckLowerBound< T > ( value,
min,
String  name = null 
)
static

Checks if an argument value exceeds a lower bound.

Parameters
valuethe argument value to check
minthe lowest value that is allowed
namethe name of the argument that is tested
Returns
the argument value if it is within the bound of @paramref min
Exceptions
ArgumentOutOfRangeExceptionif the argument value is not within the bound of @paramref min
Since
0.4.0
Type Constraints
T :IComparable 

◆ CheckNotNull< TValue >() [1/2]

static TValue Joutsen.Precondition.CheckNotNull< TValue > ( TValue  value,
Exception  exception 
)
static

Checks if a value is null and throws the exception if it is.

Parameters
TValuethe type of the value that is checked
valuethe value that is checked
exceptionthe exception to throw if the value is null
Returns
the input value if it is not null
Since
0.5.0
Type Constraints
TValue :class 

◆ CheckNotNull< TValue >() [2/2]

static TValue Joutsen.Precondition.CheckNotNull< TValue > ( TValue  value,
String  name = null 
)
static

Checks if a value is null and throws an System.ArgumentNullException if it is.

Parameters
TValuethe type of the value that is checked
valuethe value that is checked
nameoptional, the name of the parameter that refers to the checked value
Returns
the input value if it is not null
Exceptions
System.ArgumentNullExceptionif value is null
Type Constraints
TValue :class 

◆ CheckNotNullOrEmpty() [1/2]

static String Joutsen.Precondition.CheckNotNullOrEmpty ( String  value,
Exception  exception 
)
static

Checks if a String value is null or an empty string and raises an System.ArgumentException if it is.

Parameters
valuethe value that is checked
exceptionthe exception to throw if the value is null
Returns
the input value if it is not null or an empty string
Since
0.5.0

◆ CheckNotNullOrEmpty() [2/2]

static String Joutsen.Precondition.CheckNotNullOrEmpty ( String  value,
String  name = null 
)
static

Checks if a String value is null or an empty string and raises an System.ArgumentException if it is.

Parameters
valuethe value that is checked
nameoptional, the name of the parameter that refers to the checked value
Returns
the input value if it is not null or an empty string
Exceptions
System.ArgumentNullExceptionif value is null
System.ArgumentExceptionif value is an empty string

◆ CheckNotNullOrWhiteSpace() [1/2]

static String Joutsen.Precondition.CheckNotNullOrWhiteSpace ( String  value,
Exception  exception 
)
static

Checks if a string argument is null or consists only out of invisible or white space characters.

Parameters
valuethe string to check
exceptionthe exception to throw if the value is null
Returns
the string value if it does not only consist of white space characters or is null
Since
0.5.0

◆ CheckNotNullOrWhiteSpace() [2/2]

static String Joutsen.Precondition.CheckNotNullOrWhiteSpace ( String  value,
String  name = null 
)
static

Checks if a string argument is null or consists only out of invisible or white space characters.

Parameters
valuethe string to check
namethe name of the argument that is tested
Returns
the string value if it does not only consist of white space characters or is null
Exceptions
ArgumentNullExceptionif the string is null
ArgumentExceptionif the string is empty or only contains of white space characters
Since
0.4.0

◆ CheckRange< T >() [1/2]

static T Joutsen.Precondition.CheckRange< T > ( value,
min,
max,
Exception  exception 
)
static

Checks if an argument value is between an upper and lower bound.

Parameters
valuethe argument value to check
minthe lowest value that is allowed
maxthe highest value that is allowed
exceptionthe exception to throw if the value is not within the range of @paramref min and @paramref max
Returns
the argument value if it is within the range of @paramref min and @paramref max
Since
0.5.0
Type Constraints
T :IComparable 

◆ CheckRange< T >() [2/2]

static T Joutsen.Precondition.CheckRange< T > ( value,
min,
max,
String  name = null 
)
static

Checks if an argument value is between an upper and lower bound.

Parameters
valuethe argument value to check
minthe lowest value that is allowed
maxthe highest value that is allowed
namethe name of the argument that is tested
Returns
the argument value if it is within the range of @paramref min and @paramref max
Exceptions
ArgumentOutOfRangeExceptionif the argument value is not within the range of @paramref min and @paramref max
Since
0.4.0
Type Constraints
T :IComparable 

◆ CheckType< T >() [1/2]

static T Joutsen.Precondition.CheckType< T > ( object  value,
Exception  exception 
)
static

Checks if an argument value is of a certain type.

Parameters
valuethe argument value to check
exceptionthe exception to throw if the value is not the required type @typeparamref T
Returns
the argument value as type @typeparamref T
Since
Unreleased

◆ CheckType< T >() [2/2]

static T Joutsen.Precondition.CheckType< T > ( object  value,
String  name = null 
)
static

Checks if an argument value is of a certain type.

Parameters
valuethe argument value to check
namethe name of the argument that is tested
Returns
the argument value as type @typeparamref T
Exceptions
ArgumentExceptionif the argument value is not of the required type @typeparamref T
Since
Unreleased

◆ CheckUpperBound< T >() [1/2]

static T Joutsen.Precondition.CheckUpperBound< T > ( value,
max,
Exception  exception 
)
static

Checks if an argument value is below an upper bound.

Parameters
valuethe argument value to check
maxthe highest value that is allowed
exceptionthe exception to throw if the value is not within the bound of @paramref max
Returns
the argument value if it is within the bound of @paramref max
Since
0.5.0
Type Constraints
T :IComparable 

◆ CheckUpperBound< T >() [2/2]

static T Joutsen.Precondition.CheckUpperBound< T > ( value,
max,
String  name = null 
)
static

Checks if an argument value is below an upper bound.

Parameters
valuethe argument value to check
maxthe highest value that is allowed
namethe name of the argument that is tested
Returns
the argument value if it is within the bound of @paramref max
Exceptions
ArgumentOutOfRangeExceptionif the argument value is not within the bound of @paramref max
Since
0.4.0
Type Constraints
T :IComparable