Class ValidationResult
Represents the result of a validation operation, including success status and error details.
Inherited Members
Namespace: ValidationFramework
Assembly: ValidationFramework.dll
Syntax
public class ValidationResult
Properties
| Edit this page View SourceErrors
Gets the list of all validation errors.
Declaration
public List<string> Errors { get; }
Property Value
| Type | Description |
|---|---|
| List<string> |
FieldErrors
Gets the dictionary of field-specific validation errors.
Declaration
public Dictionary<string, List<string>> FieldErrors { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, List<string>> |
IsValid
Gets or sets whether validation succeeded. A result containing errors is always invalid.
Declaration
public bool IsValid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Success
Gets a new successful result with independent error collections.
Declaration
public static ValidationResult Success { get; }
Property Value
| Type | Description |
|---|---|
| ValidationResult |
Methods
| Edit this page View SourceAddError(string)
Adds a general validation error message.
Declaration
public void AddError(string error)
Parameters
| Type | Name | Description |
|---|---|---|
| string | error | The error message to add. |
AddFieldError(string, string)
Adds an error message associated with a specific field.
Declaration
public void AddFieldError(string fieldName, string error)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field with the error. |
| string | error | The error message. |
GetFieldErrors(string)
Retrieves all error messages for a specific field.
Declaration
public IReadOnlyList<string> GetFieldErrors(string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | A read-only list of error messages for the field, or an empty list if none exist. |
GetFirstFieldError(string)
Retrieves the first error message for a specific field.
Declaration
public string? GetFirstFieldError(string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field. |
Returns
| Type | Description |
|---|---|
| string | The first error message for the field, or null if none exist. |
ToErrorDictionary()
Converts errors to a dictionary suitable for model state or other UI frameworks. General errors use the empty-string key.
Declaration
public Dictionary<string, string[]> ToErrorDictionary()
Returns
| Type | Description |
|---|---|
| Dictionary<string, string[]> | A dictionary mapping field names to arrays of error messages. |