Search Results for

    Show / Hide Table of Contents

    Class ValidationResult

    Represents the result of data validation containing information about validity, errors, and warnings.

    Inheritance
    System.Object
    ValidationResult
    Namespace: IronBarCode
    Assembly: IronBarCode.dll
    Syntax
    public class ValidationResult : Object

    Reporting whether scanned barcode data passed a custom rule runs through ValidationResult. It represents the outcome of validating a decoded value, carrying a pass or fail flag along with any error and warning messages collected during the check. A developer meets this type when wiring custom validation into barcode reading, where a rule decides whether a decoded payload, such as a SKU or serial format, is acceptable.

    A ValidationResult is produced rather than configured. The validation function supplied to an IdentifierDefinition, a Func<string, ValidationResult>, returns one for each value it inspects, and IronBarcode reads it to decide whether the data is valid. Code writes a ValidationResult from inside a validator and reads it where the validation outcome is consumed, so the same type bridges the rule and the caller that acts on it.

    Three static factory methods build the common outcomes without manual construction. Valid() returns a passing result, Invalid(string) returns a failing result carrying the error message supplied, and Warning(string) returns a result that flags a concern without failing outright. On the returned object, IsValid reports the boolean verdict, Errors lists the failure messages as a List<string>, and Warnings lists the non-fatal notes the same way. A validator typically returns ValidationResult.Valid() when a value matches its expected format and ValidationResult.Invalid("reason") when it does not, and the consuming code then checks IsValid and surfaces Errors to the user. Use the factory methods to produce results and the properties to inspect them.

    using IronBarCode;
    
    ValidationResult result =
        value.Length == 8 ? ValidationResult.Valid() : ValidationResult.Invalid("Expected 8 digits");
    if (!result.IsValid)
        Console.WriteLine(string.Join(", ", result.Errors));

    The checksum and format validation how-to covers validating decoded data, the detailed error messages how-to surfaces validation output, and the read barcodes from images how-to shows the read these rules check.

    Constructors

    ValidationResult()

    Declaration
    public ValidationResult()

    Properties

    Errors

    List of validation errors.

    Declaration
    public List<string> Errors { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.List<System.String>

    IsValid

    Indicates whether the validation was successful.

    Declaration
    public bool IsValid { get; set; }
    Property Value
    Type Description
    System.Boolean

    Warnings

    List of validation warnings.

    Declaration
    public List<string> Warnings { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.List<System.String>

    Methods

    Invalid(String)

    Creates an invalid validation result with the specified error message.

    Declaration
    public static ValidationResult Invalid(string error)
    Parameters
    Type Name Description
    System.String error

    The error message describing the validation failure.

    Returns
    Type Description
    ValidationResult

    An invalid ValidationResult instance with the specified error.

    Valid()

    Creates a valid validation result with no errors or warnings.

    Declaration
    public static ValidationResult Valid()
    Returns
    Type Description
    ValidationResult

    A valid ValidationResult instance.

    Warning(String)

    Creates a valid validation result with a warning message.

    Declaration
    public static ValidationResult Warning(string error)
    Parameters
    Type Name Description
    System.String error

    The warning message.

    Returns
    Type Description
    ValidationResult

    A valid ValidationResult instance with the specified warning.

    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget