Class ValidationError

Namespace
REslava.Result
Assembly
REslava.Result.dll

Represents a validation error (HTTP 400/422 equivalent). Use when input data fails validation rules.

public class ValidationError : Reason<ValidationError>, IReasonMetadata, IError, IReason, IErrorFactory<ValidationError>
Inheritance
ValidationError
Implements
Inherited Members
Extension Methods

Examples

Result<User>.Fail(ValidationError.Field("Email", "Invalid email format"));
Result<User>.Fail(new ValidationError("Name is required"));

Constructors

ValidationError(string, string)

[Obsolete("Use ValidationError.Field(fieldName, message) for field-specific validation errors. This constructor will be removed in a future version.")]
public ValidationError(string fieldName, string message)

Parameters

fieldName string
message string

ValidationError(string, string?, string?, int)

public ValidationError(string message, string? callerMember = null, string? callerFile = null, int callerLine = 0)

Parameters

message string
callerMember string
callerFile string
callerLine int

Properties

FieldName

public string? FieldName { get; }

Property Value

string

Methods

Create(string)

Creates an instance of ValidationError with the given message.

public static ValidationError Create(string message)

Parameters

message string

Returns

ValidationError

CreateNew(string, ImmutableDictionary<string, object>)

Factory method for creating new instances (maintains immutability). Must be implemented by derived classes.

protected override ValidationError CreateNew(string message, ImmutableDictionary<string, object> tags)

Parameters

message string
tags ImmutableDictionary<string, object>

Returns

ValidationError

Field(string, string, string?, string?, int)

Creates a validation error for a specific field, capturing the calling method name automatically.

public static ValidationError Field(string fieldName, string message, string? callerMember = null, string? callerFile = null, int callerLine = 0)

Parameters

fieldName string
message string
callerMember string
callerFile string
callerLine int

Returns

ValidationError