Header menu logo TDesu.FSharp

Guard Module

Guard module — validate-and-throw in one call.

All guards are inline for zero-cost abstraction at call sites.

Functions and values

Function or value Description

Guard.inRange paramName lo hi value

Full Usage: Guard.inRange paramName lo hi value

Parameters:
    paramName : string - Name of the parameter for the exception.
    lo : 'T - Inclusive lower bound.
    hi : 'T - Inclusive upper bound.
    value : 'T - Value to validate.

Modifiers: inline
Type parameters: 'T

Throws ArgumentOutOfRangeException if value is not between lo and hi (inclusive).

paramName : string

Name of the parameter for the exception.

lo : 'T

Inclusive lower bound.

hi : 'T

Inclusive upper bound.

value : 'T

Value to validate.

ArgumentOutOfRangeException When value is outside [lo, hi].

Guard.isFalse paramName msg condition

Full Usage: Guard.isFalse paramName msg condition

Parameters:
    paramName : string - Name of the parameter for the exception.
    msg : string - Exception message.
    condition : bool - Condition that must be false.

Modifiers: inline

Throws ArgumentException if condition is true.

paramName : string

Name of the parameter for the exception.

msg : string

Exception message.

condition : bool

Condition that must be false.

ArgumentException When condition is true.

Guard.isTrue paramName msg condition

Full Usage: Guard.isTrue paramName msg condition

Parameters:
    paramName : string - Name of the parameter for the exception.
    msg : string - Exception message.
    condition : bool - Condition that must be true.

Modifiers: inline

Throws ArgumentException if condition is false.

paramName : string

Name of the parameter for the exception.

msg : string

Exception message.

condition : bool

Condition that must be true.

ArgumentException When condition is false.

Guard.notEmpty paramName value

Full Usage: Guard.notEmpty paramName value

Parameters:
    paramName : string - Name of the parameter for the exception.
    value : string - String to check.

Modifiers: inline

Throws ArgumentException if string is null or empty.

paramName : string

Name of the parameter for the exception.

value : string

String to check.

ArgumentException When value is null or empty.

Guard.notNegative paramName value

Full Usage: Guard.notNegative paramName value

Parameters:
    paramName : string - Name of the parameter for the exception.
    value : ^T - Value that must not be negative.

Modifiers: inline
Type parameters: ^T

Throws ArgumentOutOfRangeException if value is negative.

paramName : string

Name of the parameter for the exception.

value : ^T

Value that must not be negative.

ArgumentOutOfRangeException When value < 0.

Guard.notNull paramName value

Full Usage: Guard.notNull paramName value

Parameters:
    paramName : string - Name of the parameter for the exception.
    value : 'T - Value to check for null.

Modifiers: inline
Type parameters: 'T

Throws ArgumentNullException if value is null.

paramName : string

Name of the parameter for the exception.

value : 'T

Value to check for null.

ArgumentNullException When value is null.

Guard.notWhiteSpace paramName value

Full Usage: Guard.notWhiteSpace paramName value

Parameters:
    paramName : string - Name of the parameter for the exception.
    value : string - String to check.

Modifiers: inline

Throws ArgumentException if string is null, empty, or whitespace.

paramName : string

Name of the parameter for the exception.

value : string

String to check.

ArgumentException When value is null, empty, or whitespace.

Guard.positive paramName value

Full Usage: Guard.positive paramName value

Parameters:
    paramName : string - Name of the parameter for the exception.
    value : ^T - Value that must be positive.

Modifiers: inline
Type parameters: ^T

Throws ArgumentOutOfRangeException if value is less than or equal to zero.

paramName : string

Name of the parameter for the exception.

value : ^T

Value that must be positive.

ArgumentOutOfRangeException When value <= 0.

Type something to start searching.