Class GaxPreconditions

public static class GaxPreconditions

Preconditions for checking method arguments, state etc.

Inheritance

Object > GaxPreconditions

Namespace

Google.Api.Gax

Assembly

Google.Api.Gax.dll

Methods

CheckArgument(Boolean, String, String)

public static void CheckArgument(bool condition, string paramName, string message)

Checks that given argument-based condition is met, throwing an ArgumentException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

StringparamName

The name of the parameter whose value is being tested.

Stringmessage

The message to include in the exception, if generated. This should not use interpolation, as the interpolation would be performed regardless of whether or not an exception is thrown.

CheckArgument<T>(Boolean, String, String, T)

public static void CheckArgument<T>(bool condition, string paramName, string format, T arg0)

Checks that given argument-based condition is met, throwing an ArgumentException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

StringparamName

The name of the parameter whose value is being tested.

Stringformat

The format string to use to create the exception message if the condition is not met.

Targ0

The argument to the format string.

Type Parameter
NameDescription
T

CheckArgument<T1, T2>(Boolean, String, String, T1, T2)

public static void CheckArgument<T1, T2>(bool condition, string paramName, string format, T1 arg0, T2 arg1)

Checks that given argument-based condition is met, throwing an ArgumentException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

StringparamName

The name of the parameter whose value is being tested.

Stringformat

The format string to use to create the exception message if the condition is not met.

T1arg0

The first argument to the format string.

T2arg1

The second argument to the format string.

Type Parameters
NameDescription
T1
T2

CheckArgumentRange(Int32, String, Int32, Int32)

public static int CheckArgumentRange(int argument, string paramName, int minInclusive, int maxInclusive)

Checks that the given argument value is valid.

Parameters
TypeNameDescription
Int32argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Int32minInclusive

The smallest valid value.

Int32maxInclusive

The largest valid value.

Returns
TypeDescription
Int32

argument if it was in range

Remarks

Note that the upper bound (maxInclusive) is inclusive, not exclusive. This is deliberate, to allow the specification of ranges which include MaxValue.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was outside the specified range.

CheckArgumentRange<T>(T, String, T, T)

public static T CheckArgumentRange<T>(T argument, string paramName, T minInclusive, T maxInclusive)
    where T : IComparable<T>

Checks that the given argument value is valid.

Parameters
TypeNameDescription
Targument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

TminInclusive

The smallest valid value.

TmaxInclusive

The largest valid value.

Returns
TypeDescription
T

argument if it was in range

Type Parameter
NameDescription
T
Remarks

Note that the upper bound (maxInclusive) is inclusive, not exclusive. This is deliberate, to allow the specification of ranges which include MaxValue.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was outside the specified range.

CheckArgumentRange<T>(Nullable<T>, String, T, T)

public static T? CheckArgumentRange<T>(T? argument, string paramName, T minInclusive, T maxInclusive)
    where T : struct, IComparable<T>

Checks that the given argument value, if not null, is valid.

Parameters
TypeNameDescription
Nullable<T>argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

TminInclusive

The smallest valid value.

TmaxInclusive

The largest valid value.

Returns
TypeDescription
Nullable<T>

argument if it was in range, or null.

Type Parameter
NameDescription
T
Remarks

Note that the upper bound (maxInclusive) is inclusive, not exclusive. This is deliberate, to allow the specification of ranges which include MaxValue.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was outside the specified range.

CheckEnumValue<T>(T, String)

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

Checks that the given value is in fact defined in the enum used as the type argument of the method.

Parameters
TypeNameDescription
Tvalue

The value to check.

StringparamName

The name of the parameter whose value is being tested.

Returns
TypeDescription
T

value if it was a defined value

Type Parameter
NameDescription
T

The enum type to check the value within.

CheckNonNegative(Double, String)

public static double CheckNonNegative(double argument, string paramName)

Checks that the given argument value is not negative.

Parameters
TypeNameDescription
Doubleargument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Double

argument if it was non-negative.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegative(Int32, String)

public static int CheckNonNegative(int argument, string paramName)

Checks that the given argument value is not negative.

Parameters
TypeNameDescription
Int32argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Int32

argument if it was non-negative.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegative(Int64, String)

public static long CheckNonNegative(long argument, string paramName)

Checks that the given argument value is not negative.

Parameters
TypeNameDescription
Int64argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Int64

argument if it was non-negative.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegative(Nullable<Double>, String)

public static double? CheckNonNegative(double? argument, string paramName)

Checks that the given argument value, if not null, is not negative.

Parameters
TypeNameDescription
Nullable<Double>argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Nullable<Double>

argument if it was non-negative, or null.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegative(Nullable<Int32>, String)

public static int? CheckNonNegative(int? argument, string paramName)

Checks that the given argument value, if not null, is not negative.

Parameters
TypeNameDescription
Nullable<Int32>argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Nullable<Int32>

argument if it was non-negative, or null.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegative(Nullable<Int64>, String)

public static long? CheckNonNegative(long? argument, string paramName)

Checks that the given argument value, if not null, is not negative.

Parameters
TypeNameDescription
Nullable<Int64>argument

The value of the argument passed to the calling method.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
Nullable<Int64>

argument if it was non-negative, or null.

Exceptions
TypeCondition
ArgumentOutOfRangeException

The argument was negative.

CheckNonNegativeDelay(TimeSpan, String)

public static TimeSpan CheckNonNegativeDelay(TimeSpan value, string paramName)

Checks that the given TimeSpan used as a delay is non-negative. This is a very specific call; most users won't need it.

Parameters
TypeNameDescription
TimeSpanvalue

The value to check.

StringparamName

The name of the parameter whose value is being tested.

Returns
TypeDescription
TimeSpan

CheckNotNull<T>(T, String)

public static T CheckNotNull<T>(T argument, string paramName)
    where T : class

Checks that the given argument (to the calling method) is non-null.

Parameters
TypeNameDescription
Targument

The argument provided for the parameter.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
T

argument if it is not null

Type Parameter
NameDescription
T

The type of the parameter.

Exceptions
TypeCondition
ArgumentNullException

argument is null

CheckNotNullOrEmpty(String, String)

public static string CheckNotNullOrEmpty(string argument, string paramName)

Checks that a string argument is neither null, nor an empty string.

Parameters
TypeNameDescription
Stringargument

The argument provided for the parameter.

StringparamName

The name of the parameter in the calling method.

Returns
TypeDescription
String

argument if it is not null or empty

Exceptions
TypeCondition
ArgumentNullException

argument is null

ArgumentException

argument is empty

CheckState(Boolean, String)

public static void CheckState(bool condition, string message)

Checks that given condition is met, throwing an InvalidOperationException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

Stringmessage

The message to include in the exception, if generated. This should not use interpolation, as the interpolation would be performed regardless of whether or not an exception is thrown.

CheckState<T>(Boolean, String, T)

public static void CheckState<T>(bool condition, string format, T arg0)

Checks that given condition is met, throwing an InvalidOperationException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

Stringformat

The format string to use to create the exception message if the condition is not met.

Targ0

The argument to the format string.

Type Parameter
NameDescription
T

CheckState<T1, T2>(Boolean, String, T1, T2)

public static void CheckState<T1, T2>(bool condition, string format, T1 arg0, T2 arg1)

Checks that given condition is met, throwing an InvalidOperationException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

Stringformat

The format string to use to create the exception message if the condition is not met.

T1arg0

The first argument to the format string.

T2arg1

The second argument to the format string.

Type Parameters
NameDescription
T1
T2

CheckState<T1, T2, T3>(Boolean, String, T1, T2, T3)

public static void CheckState<T1, T2, T3>(bool condition, string format, T1 arg0, T2 arg1, T3 arg2)

Checks that given condition is met, throwing an InvalidOperationException otherwise.

Parameters
TypeNameDescription
Booleancondition

The (already evaluated) condition to check.

Stringformat

The format string to use to create the exception message if the condition is not met.

T1arg0

The first argument to the format string.

T2arg1

The second argument to the format string.

T3arg2

The third argument to the format string.

Type Parameters
NameDescription
T1
T2
T3