4.10.0 (latest) 4.8.0 4.4.0 4.3.1 4.2.0 4.0.0 3.2.0

    public static class GaxPreconditions

Preconditions for checking method arguments, state etc.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> GaxPreconditions

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Api.Gax](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.md.txt)

## Assembly

Google.Api.Gax.dll

## Methods

### CheckArgument(bool, string, string)

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

Checks that given argument-based condition is met, throwing an [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `paramName` | `string` The name of the parameter whose value is being tested. |
| `message` | `string` 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. |

### CheckArgumentRange(int, string, int, int)

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

Checks that the given argument value is valid.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `int` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |
| `minInclusive` | `int` The smallest valid value. |
| `maxInclusive` | `int` The largest valid value. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | `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](https://learn.microsoft.com/dotnet/api/system.int32.maxvalue).

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `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 : struct, IComparable<T>

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |
| `minInclusive` | `T` The smallest valid value. |
| `maxInclusive` | `T` The largest valid value. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
|   | `argument` if it was in range, or `null`. |

| **Type Parameter** ||
|---|---|
| **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
[MaxValue](https://learn.microsoft.com/dotnet/api/system.int32.maxvalue).

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `argument` | `T` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |
| `minInclusive` | `T` The smallest valid value. |
| `maxInclusive` | `T` The largest valid value. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | `argument` if it was in range |

| **Type Parameter** ||
|---|---|
| **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
[MaxValue](https://learn.microsoft.com/dotnet/api/system.int64.maxvalue).

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was outside the specified range. |

### CheckArgument\<T\>(bool, 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](https://learn.microsoft.com/dotnet/api/system.argumentexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `paramName` | `string` The name of the parameter whose value is being tested. |
| `format` | `string` The format string to use to create the exception message if the condition is not met. |
| `arg0` | `T` The argument to the format string. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

### CheckArgument\<T1, T2\>(bool, 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](https://learn.microsoft.com/dotnet/api/system.argumentexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `paramName` | `string` The name of the parameter whose value is being tested. |
| `format` | `string` The format string to use to create the exception message if the condition is not met. |
| `arg0` | `T1` The first argument to the format string. |
| `arg1` | `T2` The second argument to the format string. |

| **Type Parameters** ||
|---|---|
| **Name** | **Description** |
| `T1` |   |
| `T2` |   |

### 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** ||
|---|---|
| **Name** | **Description** |
| `value` | `T` The value to check. |
| `paramName` | `string` The name of the parameter whose value is being tested. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | `value` if it was a defined value |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `argument` | `double` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `double` | `argument` if it was non-negative. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegative(int, string)

    public static int CheckNonNegative(int argument, string paramName)

Checks that the given argument value is not negative.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `int` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | `argument` if it was non-negative. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegative(long, string)

    public static long CheckNonNegative(long argument, string paramName)

Checks that the given argument value is not negative.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `long` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `long` | `argument` if it was non-negative. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegative(double?, string)

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

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `double` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `double` | `argument` if it was non-negative, or `null`. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegative(int?, string)

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

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `int` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | `argument` if it was non-negative, or `null`. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegative(long?, string)

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

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `long` The value of the argument passed to the calling method. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `long` | `argument` if it was non-negative, or `null`. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentOutOfRangeException` | The argument was negative. |

### CheckNonNegativeDelay(TimeSpan, string)

    public static TimeSpan CheckNonNegativeDelay(TimeSpan value, string paramName)

Checks that the given [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) used as a delay is non-negative. This is a very specific
call; most users won't need it.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `value` | `TimeSpan` The value to check. |
| `paramName` | `string` The name of the parameter whose value is being tested. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TimeSpan` |   |

### CheckNotNullOrEmpty(string, string)

    public static string CheckNotNullOrEmpty(string argument, string paramName)

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `argument` | `string` The argument provided for the parameter. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` | `argument` if it is not null or empty |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentNullException` | `argument` is null |
| `ArgumentException` | `argument` is empty |

### 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** ||
|---|---|
| **Name** | **Description** |
| `argument` | `T` The argument provided for the parameter. |
| `paramName` | `string` The name of the parameter in the calling method. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | `argument` if it is not null |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type of the parameter. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `ArgumentNullException` | `argument` is null |

### CheckState(bool, string)

    public static void CheckState(bool condition, string message)

Checks that given condition is met, throwing an [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `message` | `string` 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\>(bool, string, T)

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

Checks that given condition is met, throwing an [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `format` | `string` The format string to use to create the exception message if the condition is not met. |
| `arg0` | `T` The argument to the format string. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

### CheckState\<T1, T2\>(bool, 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](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `format` | `string` The format string to use to create the exception message if the condition is not met. |
| `arg0` | `T1` The first argument to the format string. |
| `arg1` | `T2` The second argument to the format string. |

| **Type Parameters** ||
|---|---|
| **Name** | **Description** |
| `T1` |   |
| `T2` |   |

### CheckState\<T1, T2, T3\>(bool, 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](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) otherwise.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `condition` | `bool` The (already evaluated) condition to check. |
| `format` | `string` The format string to use to create the exception message if the condition is not met. |
| `arg0` | `T1` The first argument to the format string. |
| `arg1` | `T2` The second argument to the format string. |
| `arg2` | `T3` The third argument to the format string. |

| **Type Parameters** ||
|---|---|
| **Name** | **Description** |
| `T1` |   |
| `T2` |   |
| `T3` |   |