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
ReasonCodestringNon-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 withkebab-caseinside a segment.FieldsEquatableArray<InputPointer>Optional pointers to fields involved in the rule (used to highlight related inputs in a UI when no single field carries the violation).
ArgsImmutableDictionary<string, ValidationArgValue>Optional structured arguments for the renderer. Build them with ValidationArgs. Compared by value contents.
DetailstringOptional 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
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
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
ReasonCode
Stable machine-readable code identifying the rule that was violated.
public string ReasonCode { get; init; }
Property Value
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
otherRuleViolationAn object to compare with this object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.