Class FieldViolation
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Describes a validation failure attached to a specific field of an input document. Used inside Error.InvalidInput.
public sealed record FieldViolation : IEquatable<FieldViolation>
- Inheritance
-
FieldViolation
- Implements
- Inherited Members
- Extension Methods
Constructors
FieldViolation(InputPointer, string, ImmutableDictionary<string, ValidationArgValue>?, string?)
Describes a validation failure attached to a specific field of an input document. Used inside Error.InvalidInput.
public FieldViolation(InputPointer Field, string ReasonCode, ImmutableDictionary<string, ValidationArgValue>? Args = null, string? Detail = null)
Parameters
FieldInputPointerJSON Pointer locating the offending field.
ReasonCodestringNon-blank machine-readable code identifying the rule that was violated. Prefer a ValidationCodes constant (e.g. ValueNotNull, StringLength, StringPattern); an application-specific code should follow the same convention — lower-case, dot-separated namespaces with
kebab-caseinside a segment.ArgsImmutableDictionary<string, ValidationArgValue>Optional structured arguments for the renderer (e.g.
{ "min": 3, "max": 50 }for a length-range violation). 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 (e.g. { "min": 3, "max": 50 }
for a length-range violation). 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
Field
JSON Pointer locating the offending field.
public InputPointer Field { 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. The violation is
the atom that is created once when a rule fires and only copied afterwards, which is why
the count lives here rather than on the carrying Error.InvalidInput — that is
rebuilt during pointer rebasing and error aggregation, and would count one firing several
times. A with-expression does not recount. Codes are validated before recording a metric.
Exceptions
- ArgumentException
The assigned code is null, empty, or whitespace.
Methods
Equals(FieldViolation?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(FieldViolation? other)
Parameters
otherFieldViolationAn 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.
Required(string?, string?)
Creates a required-field violation with ValueNotNull.
public static FieldViolation Required(string? fieldName, string? detail = null)
Parameters
fieldNamestringProperty name or full JSON Pointer; null or empty targets the root.
detailstringOptional human-readable violation detail.
Returns
- FieldViolation
A required-field violation without structured arguments.
Required(InputPointer, string?)
Creates a required-field violation preserving the supplied pointer and input location.
public static FieldViolation Required(InputPointer field, string? detail = null)
Parameters
fieldInputPointerThe pointer locating the missing field.
detailstringOptional human-readable violation detail.
Returns
- FieldViolation
A violation with ValueNotNull and no structured arguments.