Table of Contents

Class RuleViolation

Namespace
Trellis
Assembly
Trellis.Core.dll

Describes a global or multi-field business-rule failure attached to a Error.InvalidInput. Use this for invariant violations that are not bound to a single field (e.g. "order.must-have-items", "password.mismatch", "order.cancel-after-ship").

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

Constructors

RuleViolation(string, EquatableArray<InputPointer>, ImmutableDictionary<string, ValidationArgValue>?, string?)

Describes a global or multi-field business-rule failure attached to a Error.InvalidInput. Use this for invariant violations that are not bound to a single field (e.g. "order.must-have-items", "password.mismatch", "order.cancel-after-ship").

public RuleViolation(string ReasonCode, EquatableArray<InputPointer> Fields = default, ImmutableDictionary<string, ValidationArgValue>? Args = null, string? Detail = null)

Parameters

ReasonCode string

Non-blank machine-readable code identifying the rule. The framework's own cross-field rules use the fields.* namespace of ValidationCodes (e.g. FieldsMutuallyExclusive); an application-specific rule code should follow the same convention — lower-case, dot-separated namespaces with kebab-case inside a segment.

Fields EquatableArray<InputPointer>

Optional pointers to fields involved in the rule (used to highlight related inputs in a UI when no single field carries the violation).

Args ImmutableDictionary<string, ValidationArgValue>

Optional structured arguments for the renderer. Build them with ValidationArgs. Compared by value contents.

Detail string

Optional caller-supplied detail string. When non-null the boundary renderer prefers this over the default template for ReasonCode.

Properties

Args

Optional structured arguments for the renderer. Build them with ValidationArgs. Compared by value contents.

public ImmutableDictionary<string, ValidationArgValue>? Args { get; init; }

Property Value

ImmutableDictionary<string, ValidationArgValue>

Detail

Optional caller-supplied detail string. When non-null the boundary renderer prefers this over the default template for ReasonCode.

public string? Detail { get; init; }

Property Value

string

Fields

Optional pointers to fields involved in the rule (used to highlight related inputs in a UI when no single field carries the violation).

public EquatableArray<InputPointer> Fields { get; init; }

Property Value

EquatableArray<InputPointer>

ReasonCode

Stable machine-readable code identifying the rule that was violated.

public string ReasonCode { get; init; }

Property Value

string

Remarks

The initializer is the counting site for ValidationMetrics, for the reasons given on ReasonCode.

Exceptions

ArgumentException

The assigned code is null, empty, or whitespace.

Methods

Equals(RuleViolation?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(RuleViolation? other)

Parameters

other RuleViolation

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.