Class GaxPreconditions
Preconditions for checking method arguments, state etc.
Inheritance
Inherited Members
Namespace: Google.Api.Gax
Assembly: Google.Api.Gax.dll
Syntax
public static class GaxPreconditions
Methods
CheckArgument(Boolean, String, String)
Checks that given argument-based condition is met, throwing an System.ArgumentException otherwise.
Declaration
public static void CheckArgument(bool condition, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | paramName | The name of the parameter whose value is being tested. |
System.String | message | 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)
Checks that given argument-based condition is met, throwing an System.ArgumentException otherwise.
Declaration
public static void CheckArgument<T>(bool condition, string paramName, string format, T arg0)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | paramName | The name of the parameter whose value is being tested. |
System.String | format | The format string to use to create the exception message if the condition is not met. |
T | arg0 | The argument to the format string. |
Type Parameters
Name | Description |
---|---|
T |
CheckArgument<T1, T2>(Boolean, String, String, T1, T2)
Checks that given argument-based condition is met, throwing an System.ArgumentException otherwise.
Declaration
public static void CheckArgument<T1, T2>(bool condition, string paramName, string format, T1 arg0, T2 arg1)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | paramName | The name of the parameter whose value is being tested. |
System.String | format | The format string to use to create the exception message if the condition is not met. |
T1 | arg0 | The first argument to the format string. |
T2 | arg1 | The second argument to the format string. |
Type Parameters
Name | Description |
---|---|
T1 | |
T2 |
CheckArgumentRange(Int32, String, Int32, Int32)
Checks that the given argument value is valid.
Declaration
public static int CheckArgumentRange(int argument, string paramName, int minInclusive, int maxInclusive)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
System.Int32 | minInclusive | The smallest valid value. |
System.Int32 | maxInclusive | The largest valid value. |
Returns
Type | Description |
---|---|
System.Int32 |
|
Remarks
Note that the upper bound (maxInclusive
) is inclusive,
not exclusive. This is deliberate, to allow the specification of ranges which include
System.Int32.MaxValue.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was outside the specified range. |
CheckArgumentRange<T>(T, String, T, T)
Checks that the given argument value is valid.
Declaration
public static T CheckArgumentRange<T>(T argument, string paramName, T minInclusive, T maxInclusive)
where T : IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
T | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
T | minInclusive | The smallest valid value. |
T | maxInclusive | The largest valid value. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T |
Remarks
Note that the upper bound (maxInclusive
) is inclusive,
not exclusive. This is deliberate, to allow the specification of ranges which include
System.Int64.MaxValue.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was outside the specified range. |
CheckArgumentRange<T>(Nullable<T>, String, T, T)
Checks that the given argument value, if not null
, is valid.
Declaration
public static T? CheckArgumentRange<T>(T? argument, string paramName, T minInclusive, T maxInclusive)
where T : struct, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<T> | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
T | minInclusive | The smallest valid value. |
T | maxInclusive | The largest valid value. |
Returns
Type | Description |
---|---|
System.Nullable<T> |
|
Type Parameters
Name | Description |
---|---|
T |
Remarks
Note that the upper bound (maxInclusive
) is inclusive,
not exclusive. This is deliberate, to allow the specification of ranges which include
System.Int32.MaxValue.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was outside the specified range. |
CheckEnumValue<T>(T, String)
Checks that the given value is in fact defined in the enum used as the type argument of the method.
Declaration
public static T CheckEnumValue<T>(T value, string paramName)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to check. |
System.String | paramName | The name of the parameter whose value is being tested. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | The enum type to check the value within. |
CheckNonNegative(Double, String)
Checks that the given argument value is not negative.
Declaration
public static double CheckNonNegative(double argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Double | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Double |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegative(Int32, String)
Checks that the given argument value is not negative.
Declaration
public static int CheckNonNegative(int argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Int32 |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegative(Int64, String)
Checks that the given argument value is not negative.
Declaration
public static long CheckNonNegative(long argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Int64 |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegative(Nullable<Double>, String)
Checks that the given argument value, if not null
, is not negative.
Declaration
public static double? CheckNonNegative(double? argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Double> | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Nullable<System.Double> |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegative(Nullable<Int32>, String)
Checks that the given argument value, if not null
, is not negative.
Declaration
public static int? CheckNonNegative(int? argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32> | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Nullable<System.Int32> |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegative(Nullable<Int64>, String)
Checks that the given argument value, if not null
, is not negative.
Declaration
public static long? CheckNonNegative(long? argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int64> | argument | The value of the argument passed to the calling method. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.Nullable<System.Int64> |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The argument was negative. |
CheckNonNegativeDelay(TimeSpan, String)
Checks that the given System.TimeSpan used as a delay is non-negative. This is a very specific call; most users won't need it.
Declaration
public static TimeSpan CheckNonNegativeDelay(TimeSpan value, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | value | The value to check. |
System.String | paramName | The name of the parameter whose value is being tested. |
Returns
Type | Description |
---|---|
System.TimeSpan |
CheckNotNull<T>(T, String)
Checks that the given argument (to the calling method) is non-null.
Declaration
public static T CheckNotNull<T>(T argument, string paramName)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | argument | The argument provided for the parameter. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | The type of the parameter. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
CheckNotNullOrEmpty(String, String)
Checks that a string argument is neither null, nor an empty string.
Declaration
public static string CheckNotNullOrEmpty(string argument, string paramName)
Parameters
Type | Name | Description |
---|---|---|
System.String | argument | The argument provided for the parameter. |
System.String | paramName | The name of the parameter in the calling method. |
Returns
Type | Description |
---|---|
System.String |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
CheckState(Boolean, String)
Checks that given condition is met, throwing an System.InvalidOperationException otherwise.
Declaration
public static void CheckState(bool condition, string message)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | message | 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)
Checks that given condition is met, throwing an System.InvalidOperationException otherwise.
Declaration
public static void CheckState<T>(bool condition, string format, T arg0)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | format | The format string to use to create the exception message if the condition is not met. |
T | arg0 | The argument to the format string. |
Type Parameters
Name | Description |
---|---|
T |
CheckState<T1, T2>(Boolean, String, T1, T2)
Checks that given condition is met, throwing an System.InvalidOperationException otherwise.
Declaration
public static void CheckState<T1, T2>(bool condition, string format, T1 arg0, T2 arg1)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | format | The format string to use to create the exception message if the condition is not met. |
T1 | arg0 | The first argument to the format string. |
T2 | arg1 | The second argument to the format string. |
Type Parameters
Name | Description |
---|---|
T1 | |
T2 |
CheckState<T1, T2, T3>(Boolean, String, T1, T2, T3)
Checks that given condition is met, throwing an System.InvalidOperationException otherwise.
Declaration
public static void CheckState<T1, T2, T3>(bool condition, string format, T1 arg0, T2 arg1, T3 arg2)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | The (already evaluated) condition to check. |
System.String | format | The format string to use to create the exception message if the condition is not met. |
T1 | arg0 | The first argument to the format string. |
T2 | arg1 | The second argument to the format string. |
T3 | arg2 | The third argument to the format string. |
Type Parameters
Name | Description |
---|---|
T1 | |
T2 | |
T3 |