Table of Contents

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 ValidationResult

The validation result.

key string

The key to associate the error with.

expected T

The expected value for the object.

value T

The object to check.

message string

An 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 ValidationResult

The validation result.

key string

The key to associate the error with.

value T?

The object to check.

message string

An 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 ValidationResult

The validation result.

key string

The key to associate the error with.

value T

The object to check.

message string

An 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 ValidationResult

The validation result.

key string

The key to associate the error with.

forbidden T

The forbidden value for the object.

value T

The object to check.

message string

An 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 ValidationResult

The validation result.

key string

The key to associate the error with.

value T?

The object to check.

message string

An 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 ValidationResult

The validation result.

key string

The key to associate the error with.

value T

The object to check.

message string

An optional error message.

Returns

ValidationResult

The validation result.

Type Parameters

T