Class Guard
Utility class to do null
and other checks.
Inherited Members
Namespace:CacheManager.Core.Utility
Assembly:CacheManager.Core.dll
Syntax
public static class Guard
Methods
| Improve this Doc View SourceEnsure(Boolean, String, Object[])
Validates that condition is true and otherwise throws an exception.
Declaration
public static bool Ensure(bool condition, string message, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
Boolean | condition | The condition to validate. |
String | message | The message to throw if the configuration is |
Object[] | args |
|
Returns
Type | Description |
---|---|
Boolean |
|
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if condition is false. |
EnsureNotNull<T>(T, String, Object[])
Validates that value is not null
and otherwise throws an exception.
Structs
are allowed although value cannot be null
in this case.
Declaration
public static T EnsureNotNull<T>([ValidatedNotNull] T value, string message, params object[] args)where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to validate. |
String | message | The message to throw if the value is |
Object[] | args |
|
Returns
Type | Description |
---|---|
T | The value if not |
Type Parameters
Name | Description |
---|---|
T | The type of value. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if value is |
NotNull<T>(T, String)
Validates that value is not null
and otherwise throws an exception.
Structs
are allowed although value cannot be null
in this case.
Declaration
public static T NotNull<T>([ValidatedNotNull] T value, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
T | value | The parameter value to validate. |
String | parameterName | The parameter name. |
Returns
Type | Description |
---|---|
T | The value, if not |
Type Parameters
Name | Description |
---|---|
T | The type of value. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if value is |
NotNullOrEmpty(String, String)
Validates that value is not null or empty and otherwise throws an exception.
Declaration
public static string NotNullOrEmpty([ValidatedNotNull] string value, string name)
Parameters
Type | Name | Description |
---|---|---|
String | value | The parameter value to validate. |
String | name | The parameter name. |
Returns
Type | Description |
---|---|
String | The value, if not null or empty. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if value is |
ArgumentException | Thrown if value is empty. |
NotNullOrEmpty<T>(ICollection<T>, String)
Validates that value is not null or empty and otherwise throws an exception.
Declaration
public static ICollection<T> NotNullOrEmpty<T>([ValidatedNotNull] ICollection<T> value, string name)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | value | The parameter value to validate. |
String | name | The parameter name. |
Returns
Type | Description |
---|---|
ICollection<T> | The value, if not null or empty. |
Type Parameters
Name | Description |
---|---|
T | Type of the collection. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if value is |
ArgumentException | Thrown if value is empty. |
NotNullOrWhiteSpace(String, String)
Validates that value is not null, empty or contains whitespace only and otherwise throws an exception.
Declaration
public static string NotNullOrWhiteSpace([ValidatedNotNull] string value, string name)
Parameters
Type | Name | Description |
---|---|---|
String | value | The parameter value to validate. |
String | name | The parameter name. |
Returns
Type | Description |
---|---|
String | The value if not null or empty. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if value is |
ArgumentException | Thrown if value is empty. |