Share via


ValidationResult<TResult,TError> Struct

Definition

Represents the result of an validation that can either succeed with a valid result or failed with a specific error.

public readonly struct ValidationResult<TResult,TError> : IEquatable<Microsoft.IdentityModel.Tokens.Experimental.ValidationResult<TResult,TError>> where TError : ValidationError
type ValidationResult<'Result, 'Error (requires 'Error :> ValidationError)> = struct
Public Structure ValidationResult(Of TResult, TError)
Implements IEquatable(Of ValidationResult(Of TResult, TError))

Type Parameters

TResult

The type of the successful result value.

TError

The type of the error.

Inheritance
ValidationResult<TResult,TError>
Implements
IEquatable<ValidationResult<TResult,TError>>

Remarks

This struct implements a discriminated union pattern for validation results. It ensures that either a valid result or an error is available, but never both. This pattern helps with clear error handling and propagation.

Constructors

Name Description
ValidationResult<TResult,TError>()
Obsolete.

Empty constructor implementation to prevent creating an empty result.

ValidationResult<TResult,TError>(TError)

Creates a new instance of ValidationResult<TResult,TError> indicating a failed validation and containing error information.

ValidationResult<TResult,TError>(TResult)

Creates a new instance of ValidationResult<TResult,TError> indicating a successful validation and containing an object of the associated type.

Properties

Name Description
Error

Gets the error associated with the validation result.

Result

Gets the result associated with the validation result.

Succeeded

Gets a value indicating whether the validation succeeded.

Methods

Name Description
Equals(Object)

Determines whether the specified object is equal to the current instance of ValidationResult<TResult,TError>.

Equals(ValidationResult<TResult,TError>)

Determines whether the specified ValidationResult<TResult,TError> is equal to the current instance.

GetHashCode()

Returns the hash code for this instance of ValidationResult<TResult,TError>.

ToString()
ToValidationResult()

Casts the result to a ValidationResult<TResult,TError>.

Operators

Name Description
Equality(ValidationResult<TResult,TError>, ValidationResult<TResult,TError>)

Equality comparison operator for ValidationResult<TResult,TError>.

Implicit(TError to ValidationResult<TResult,TError>)
Implicit(TResult to ValidationResult<TResult,TError>)
Inequality(ValidationResult<TResult,TError>, ValidationResult<TResult,TError>)

Inequality comparison operator for ValidationResult<TResult,TError>.

Applies to