Table of Contents

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

Field InputPointer

JSON Pointer locating the offending field.

ReasonCode string

Non-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-case inside a segment.

Args ImmutableDictionary<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.

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 (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

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

Field

JSON Pointer locating the offending field.

public InputPointer Field { get; init; }

Property Value

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. 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

other FieldViolation

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.

Required(string?, string?)

Creates a required-field violation with ValueNotNull.

public static FieldViolation Required(string? fieldName, string? detail = null)

Parameters

fieldName string

Property name or full JSON Pointer; null or empty targets the root.

detail string

Optional 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

field InputPointer

The pointer locating the missing field.

detail string

Optional human-readable violation detail.

Returns

FieldViolation

A violation with ValueNotNull and no structured arguments.