Class ValidationResult

Namespace
Cratis.Arc.Validation
Assembly
Cratis.Arc.Core.dll

Represents the an failed validation rule.

public record ValidationResult : IEquatable<ValidationResult>
Inheritance
ValidationResult
Implements
Inherited Members
Extension Methods

Remarks

State belongs to whoever authored the rule - it carries FluentValidation's WithState value straight through - so it is not where the framework says what kind of rejection this is. That is Reason, and which specific thing within that category is ReasonDetail.

Constructors

ValidationResult(ValidationResult)

protected ValidationResult(ValidationResult original)

Parameters

original ValidationResult

ValidationResult(ValidationResultSeverity, string, IEnumerable<string>, object)

Represents the an failed validation rule.

public ValidationResult(ValidationResultSeverity Severity, string Message, IEnumerable<string> Members, object State)

Parameters

Severity ValidationResultSeverity

The ValidationResultSeverity of the result.

Message string

Message of the error.

Members IEnumerable<string>

Collection of camelCase field paths that caused the failure.

State object

State associated with the validation result.

Remarks

State belongs to whoever authored the rule - it carries FluentValidation's WithState value straight through - so it is not where the framework says what kind of rejection this is. That is Reason, and which specific thing within that category is ReasonDetail.

Properties

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

Members

Gets the affected members, reported as camelCase field paths.

public IEnumerable<string> Members { get; init; }

Property Value

IEnumerable<string>

Message

Message of the error.

public string Message { get; init; }

Property Value

string

Reason

Gets what composed this result. Defaults to Rule - an authored rule rejected the input - so anything the framework composes on the application's behalf has to say so.

public ValidationResultReason Reason { get; init; }

Property Value

ValidationResultReason

ReasonDetail

Gets the identity of the specific thing that produced this result within its Reason category, or null when the reason carries no finer identity. Reason says a constraint rejected the command; this says which constraint - so a client can branch on identity instead of parsing Message, which is prose written for a human and free to change.

public string? ReasonDetail { get; init; }

Property Value

string

Remarks

Deliberately a string and deliberately not named after any one reason: this type is Arc's general validation result, it does not depend on Chronicle, and every category is free to fill this in with whatever names its own rejections - a constraint name today, something else tomorrow.

Severity

The ValidationResultSeverity of the result.

public ValidationResultSeverity Severity { get; init; }

Property Value

ValidationResultSeverity

State

State associated with the validation result.

public object State { get; init; }

Property Value

object

Methods

Deconstruct(out ValidationResultSeverity, out string, out IEnumerable<string>, out object)

public void Deconstruct(out ValidationResultSeverity Severity, out string Message, out IEnumerable<string> Members, out object State)

Parameters

Severity ValidationResultSeverity
Message string
Members IEnumerable<string>
State object

Equals(ValidationResult?)

public virtual bool Equals(ValidationResult? other)

Parameters

other ValidationResult

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

Error(string, IEnumerable<string>?, object?, ValidationResultReason?, string?)

Creates a new ValidationResult representing an error.

public static ValidationResult Error(string message, IEnumerable<string>? members = null, object? state = null, ValidationResultReason? reason = null, string? reasonDetail = null)

Parameters

message string

Message of the error.

members IEnumerable<string>

Collection of member names that caused the error.

state object

State associated with the validation result.

reason ValidationResultReason

What composed the result. Defaults to Rule.

reasonDetail string

The identity of the specific thing within reason that produced the result.

Returns

ValidationResult

A ValidationResult.

GetHashCode()

public override int GetHashCode()

Returns

int

Information(string, IEnumerable<string>?, object?, ValidationResultReason?, string?)

Creates a new ValidationResult representing information.

public static ValidationResult Information(string message, IEnumerable<string>? members = null, object? state = null, ValidationResultReason? reason = null, string? reasonDetail = null)

Parameters

message string

Message of the information.

members IEnumerable<string>

Collection of member names that are related to the information.

state object

State associated with the validation result.

reason ValidationResultReason

What composed the result. Defaults to Rule.

reasonDetail string

The identity of the specific thing within reason that produced the result.

Returns

ValidationResult

A ValidationResult.

PrintMembers(StringBuilder)

protected virtual bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

bool

ToString()

public override string ToString()

Returns

string

Warning(string, IEnumerable<string>?, object?, ValidationResultReason?, string?)

Creates a new ValidationResult representing a warning.

public static ValidationResult Warning(string message, IEnumerable<string>? members = null, object? state = null, ValidationResultReason? reason = null, string? reasonDetail = null)

Parameters

message string

Message of the warning.

members IEnumerable<string>

Collection of member names that caused the warning.

state object

State associated with the validation result.

reason ValidationResultReason

What composed the result. Defaults to Rule.

reasonDetail string

The identity of the specific thing within reason that produced the result.

Returns

ValidationResult

A ValidationResult.

Operators

operator ==(ValidationResult?, ValidationResult?)

public static bool operator ==(ValidationResult? left, ValidationResult? right)

Parameters

left ValidationResult
right ValidationResult

Returns

bool

operator !=(ValidationResult?, ValidationResult?)

public static bool operator !=(ValidationResult? left, ValidationResult? right)

Parameters

left ValidationResult
right ValidationResult

Returns

bool