Table of Contents

Class Ensure

Namespace
MongoDB.Driver.Core.Misc
Assembly
MongoDB.Driver.Core.dll

Represents methods that can be used to ensure that parameter values meet expected conditions.

public static class Ensure
Inheritance
Ensure
Inherited Members

Methods

HasValue<T>(T?, string)

Ensures that the value of a parameter is not null.

public static T? HasValue<T>(T? value, string paramName) where T : struct

Parameters

value T?

The value of the parameter.

paramName string

The name of the parameter.

Returns

T?

The value of the parameter.

Type Parameters

T

Type type of the value.

IsBetween<T>(T, T, T, string)

Ensures that the value of a parameter is between a minimum and a maximum value.

public static T IsBetween<T>(T value, T min, T max, string paramName) where T : IComparable<T>

Parameters

value T

The value of the parameter.

min T

The minimum value.

max T

The maximum value.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsEqualTo<T>(T, T, string)

Ensures that the value of a parameter is equal to a comparand.

public static T IsEqualTo<T>(T value, T comparand, string paramName)

Parameters

value T

The value of the parameter.

comparand T

The comparand.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsGreaterThanOrEqualToZero(int, string)

Ensures that the value of a parameter is greater than or equal to zero.

public static int IsGreaterThanOrEqualToZero(int value, string paramName)

Parameters

value int

The value of the parameter.

paramName string

The name of the parameter.

Returns

int

The value of the parameter.

IsGreaterThanOrEqualToZero(long, string)

Ensures that the value of a parameter is greater than or equal to zero.

public static long IsGreaterThanOrEqualToZero(long value, string paramName)

Parameters

value long

The value of the parameter.

paramName string

The name of the parameter.

Returns

long

The value of the parameter.

IsGreaterThanOrEqualToZero(TimeSpan, string)

Ensures that the value of a parameter is greater than or equal to zero.

public static TimeSpan IsGreaterThanOrEqualToZero(TimeSpan value, string paramName)

Parameters

value TimeSpan

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan

The value of the parameter.

IsGreaterThanOrEqualTo<T>(T, T, string)

Ensures that the value of a parameter is greater than or equal to a comparand.

public static T IsGreaterThanOrEqualTo<T>(T value, T comparand, string paramName) where T : IComparable<T>

Parameters

value T

The value of the parameter.

comparand T

The comparand.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsGreaterThanZero(double, string)

Ensures that the value of a parameter is greater than zero.

public static double IsGreaterThanZero(double value, string paramName)

Parameters

value double

The value of the parameter.

paramName string

The name of the parameter.

Returns

double

The value of the parameter.

IsGreaterThanZero(int, string)

Ensures that the value of a parameter is greater than zero.

public static int IsGreaterThanZero(int value, string paramName)

Parameters

value int

The value of the parameter.

paramName string

The name of the parameter.

Returns

int

The value of the parameter.

IsGreaterThanZero(long, string)

Ensures that the value of a parameter is greater than zero.

public static long IsGreaterThanZero(long value, string paramName)

Parameters

value long

The value of the parameter.

paramName string

The name of the parameter.

Returns

long

The value of the parameter.

IsGreaterThanZero(TimeSpan, string)

Ensures that the value of a parameter is greater than zero.

public static TimeSpan IsGreaterThanZero(TimeSpan value, string paramName)

Parameters

value TimeSpan

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan

The value of the parameter.

IsGreaterThan<T>(T, T, string)

Ensures that the value of a parameter is greater than a comparand.

public static T IsGreaterThan<T>(T value, T comparand, string paramName) where T : IComparable<T>

Parameters

value T

The value of the parameter.

comparand T

The comparand.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsInfiniteOrGreaterThanOrEqualToZero(TimeSpan, string)

Ensures that the value of a parameter is infinite or greater than or equal to zero.

public static TimeSpan IsInfiniteOrGreaterThanOrEqualToZero(TimeSpan value, string paramName)

Parameters

value TimeSpan

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan

The value of the parameter.

IsInfiniteOrGreaterThanZero(TimeSpan, string)

Ensures that the value of a parameter is infinite or greater than zero.

public static TimeSpan IsInfiniteOrGreaterThanZero(TimeSpan value, string paramName)

Parameters

value TimeSpan

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan

The value of the parameter.

IsNotNullAndDoesNotContainAnyNulls<T>(IEnumerable<T>, string)

Ensures that the value of a parameter is not null and does not contain any nulls.

public static IEnumerable<T> IsNotNullAndDoesNotContainAnyNulls<T>(IEnumerable<T> values, string paramName) where T : class

Parameters

values IEnumerable<T>

The value of the parameter.

paramName string

The name of the parameter.

Returns

IEnumerable<T>

The value of the parameter.

Type Parameters

T

Type of the value.

IsNotNullOrEmpty(string, string)

Ensures that the value of a parameter is not null or empty.

public static string IsNotNullOrEmpty(string value, string paramName)

Parameters

value string

The value of the parameter.

paramName string

The name of the parameter.

Returns

string

The value of the parameter.

IsNotNullOrEmpty<T>(IEnumerable<T>, string)

Ensures that the value of a parameter is not null or empty.

public static IEnumerable<T> IsNotNullOrEmpty<T>(IEnumerable<T> value, string paramName)

Parameters

value IEnumerable<T>

The value of the parameter.

paramName string

The name of the parameter.

Returns

IEnumerable<T>

The value of the parameter.

Type Parameters

T

The type of the elements.

IsNotNull<T>(T, string)

Ensures that the value of a parameter is not null.

public static T IsNotNull<T>(T value, string paramName) where T : class

Parameters

value T

The value of the parameter.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsNullOrBetween<T>(T?, T, T, string)

Ensures that the value of a parameter is null or is between a minimum and a maximum value.

public static T? IsNullOrBetween<T>(T? value, T min, T max, string paramName) where T : struct, IComparable<T>

Parameters

value T?

The value of the parameter.

min T

The minimum value.

max T

The maximum value.

paramName string

The name of the parameter.

Returns

T?

The value of the parameter.

Type Parameters

T

Type type of the value.

IsNullOrGreaterThanOrEqualToZero(int?, string)

Ensures that the value of a parameter is null or greater than or equal to zero.

public static int? IsNullOrGreaterThanOrEqualToZero(int? value, string paramName)

Parameters

value int?

The value of the parameter.

paramName string

The name of the parameter.

Returns

int?

The value of the parameter.

IsNullOrGreaterThanOrEqualToZero(long?, string)

Ensures that the value of a parameter is null or greater than or equal to zero.

public static long? IsNullOrGreaterThanOrEqualToZero(long? value, string paramName)

Parameters

value long?

The value of the parameter.

paramName string

The name of the parameter.

Returns

long?

The value of the parameter.

IsNullOrGreaterThanZero(int?, string)

Ensures that the value of a parameter is null or greater than zero.

public static int? IsNullOrGreaterThanZero(int? value, string paramName)

Parameters

value int?

The value of the parameter.

paramName string

The name of the parameter.

Returns

int?

The value of the parameter.

IsNullOrGreaterThanZero(long?, string)

Ensures that the value of a parameter is null or greater than zero.

public static long? IsNullOrGreaterThanZero(long? value, string paramName)

Parameters

value long?

The value of the parameter.

paramName string

The name of the parameter.

Returns

long?

The value of the parameter.

IsNullOrGreaterThanZero(TimeSpan?, string)

Ensures that the value of a parameter is null or greater than zero.

public static TimeSpan? IsNullOrGreaterThanZero(TimeSpan? value, string paramName)

Parameters

value TimeSpan?

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan?

The value of the parameter.

IsNullOrInfiniteOrGreaterThanOrEqualToZero(TimeSpan?, string)

Ensures that the value of a parameter is null, or infinite, or greater than or equal to zero.

public static TimeSpan? IsNullOrInfiniteOrGreaterThanOrEqualToZero(TimeSpan? value, string paramName)

Parameters

value TimeSpan?

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan?

The value of the parameter.

IsNullOrNotEmpty(string, string)

Ensures that the value of a parameter is null or not empty.

public static string IsNullOrNotEmpty(string value, string paramName)

Parameters

value string

The value of the parameter.

paramName string

The name of the parameter.

Returns

string

The value of the parameter.

IsNullOrValidTimeout(TimeSpan?, string)

Ensures that the value of a parameter is null or a valid timeout.

public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName)

Parameters

value TimeSpan?

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan?

The value of the parameter.

IsNull<T>(T, string)

Ensures that the value of a parameter is null.

public static T IsNull<T>(T value, string paramName) where T : class

Parameters

value T

The value of the parameter.

paramName string

The name of the parameter.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.

IsValidTimeout(TimeSpan, string)

Ensures that the value of a parameter is a valid timeout.

public static TimeSpan IsValidTimeout(TimeSpan value, string paramName)

Parameters

value TimeSpan

The value of the parameter.

paramName string

The name of the parameter.

Returns

TimeSpan

The value of the parameter.

That(bool, string)

Ensures that an assertion is true.

public static void That(bool assertion, string message)

Parameters

assertion bool

The assertion.

message string

The message to use with the exception that is thrown if the assertion is false.

That(bool, string, string)

Ensures that an assertion is true.

public static void That(bool assertion, string message, string paramName)

Parameters

assertion bool

The assertion.

message string

The message to use with the exception that is thrown if the assertion is false.

paramName string

The parameter name.

That<T>(T, Func<T, bool>, string, string)

Ensures that the value of a parameter meets an assertion.

public static T That<T>(T value, Func<T, bool> assertion, string paramName, string message)

Parameters

value T

The value of the parameter.

assertion Func<T, bool>

The assertion.

paramName string

The name of the parameter.

message string

The message to use with the exception that is thrown if the assertion is false.

Returns

T

The value of the parameter.

Type Parameters

T

Type type of the value.