Class ValidationError
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
ValidationError(string, string?, string?, int)
public ValidationError(string message, string? callerMember = null, string? callerFile = null, int callerLine = 0)
Parameters
Properties
FieldName
public string? FieldName { get; }
Property Value
Methods
Create(string)
Creates an instance of ValidationError with the given message.
public static ValidationError Create(string message)
Parameters
messagestring
Returns
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
messagestringtagsImmutableDictionary<string, object>
Returns
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)