Class ObjectValidationExtensions
- Namespace
- Admonish
- Assembly
- Admonish.dll
Contains object validation extension methods of ValidationResult.
public static class ObjectValidationExtensions
- Inheritance
-
ObjectValidationExtensions
- Inherited Members
Methods
Equal<T>(ValidationResult, string, T, T, string?)
Ensures that the specified object is equal to the expected one. When it is not equal, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult Equal<T>(this ValidationResult r, string key, T expected, T value, string? message = null)
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
expected
TThe expected value for the object.
value
TThe object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T
Remarks
It is recommended to specify a custom error message via
the message
parameter, because the default one
contains neither the expected value nor the checked one.
NonNull<T>(ValidationResult, string, T?, string?)
Ensures that the specified object is not null. When it is, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult NonNull<T>(this ValidationResult r, string key, T? value, string? message = null) where T : struct
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
value
T?The object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T
NonNull<T>(ValidationResult, string, T?, string?)
Ensures that the specified object is not null. When it is, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult NonNull<T>(this ValidationResult r, string key, T? value, string? message = null) where T : class
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
value
TThe object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T
NotEqual<T>(ValidationResult, string, T, T, string?)
Ensures that the specified object is not equal to the forbidden one. When it is equal, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult NotEqual<T>(this ValidationResult r, string key, T forbidden, T value, string? message = null)
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
forbidden
TThe forbidden value for the object.
value
TThe object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T
Remarks
It is recommended to specify a custom error message via
the message
parameter, because the default one
does not contain the forbidden value.
Null<T>(ValidationResult, string, T?, string?)
Ensures that the specified object is null. When it is not, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult Null<T>(this ValidationResult r, string key, T? value, string? message = null) where T : struct
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
value
T?The object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T
Null<T>(ValidationResult, string, T?, string?)
Ensures that the specified object is null. When it is not, adds an error message to the ValidationResult and associates it with the specified key.
public static ValidationResult Null<T>(this ValidationResult r, string key, T? value, string? message = null) where T : class
Parameters
r
ValidationResultThe validation result.
key
stringThe key to associate the error with.
value
TThe object to check.
message
stringAn optional error message.
Returns
- ValidationResult
The validation result.
Type Parameters
T