Validation Framework
Search Results for

    Show / Hide Table of Contents

    Class Validator<T>

    A generic validator that supports fluent API for building validation rules.

    Inheritance
    object
    Validator<T>
    Implements
    IValidator<T>
    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 Validator<T> : IValidator<T>
    Type Parameters
    Name Description
    T

    The type of value to validate.

    Constructors

    | Edit this page View Source

    Validator(string?)

    Initializes a new instance of the Validator<T> class.

    Declaration
    public Validator(string? fieldName = null)
    Parameters
    Type Name Description
    string fieldName

    Optional field name for error reporting.

    Methods

    | Edit this page View Source

    AddRule(Func<T, bool>, string)

    Adds a validation rule to this validator.

    Declaration
    public Validator<T> AddRule(Func<T, bool> rule, string errorMessage)
    Parameters
    Type Name Description
    Func<T, bool> rule

    The function that defines the validation condition.

    string errorMessage

    The error message to return if validation fails.

    Returns
    Type Description
    Validator<T>

    This validator instance for method chaining.

    | Edit this page View Source

    Validate(T)

    Validates the specified value against all rules in this validator.

    Declaration
    public ValidationResult Validate(T value)
    Parameters
    Type Name Description
    T value

    The value to validate.

    Returns
    Type Description
    ValidationResult

    A ValidationResult containing all validation errors.

    Implements

    IValidator<T>
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX