Validation Framework
Search Results for

    Show / Hide Table of Contents

    Class ValidationResult

    Represents the result of a validation operation, including success status and error details.

    Inheritance
    object
    ValidationResult
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: ValidationFramework
    Assembly: ValidationFramework.dll
    Syntax
    public class ValidationResult

    Properties

    | Edit this page View Source

    Errors

    Gets the list of all validation errors.

    Declaration
    public List<string> Errors { get; }
    Property Value
    Type Description
    List<string>
    | Edit this page View Source

    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>>
    | Edit this page View Source

    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
    | Edit this page View Source

    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 Source

    AddError(string)

    Adds a general validation error message.

    Declaration
    public void AddError(string error)
    Parameters
    Type Name Description
    string error

    The error message to add.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    Extension Methods

    AsyncValidationExtensions.Merge(ValidationResult, Task<ValidationResult>)
    AsyncValidationExtensions.MergeAsync(ValidationResult, Task<ValidationResult>)
    AsyncValidationExtensions.MergeAsync(ValidationResult, Task<ValidationResult>, CancellationToken)
    ValidationExtensions.Merge(ValidationResult, ValidationResult)
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX