Skip to content

ValidationError

NexusLabs.Needlr.Generators

ValidationError Class

Represents a validation error with optional structured information.

public sealed class ValidationError

Inheritance System.Object 🡒 ValidationError

Example

// Simple: just yield a string (implicit conversion)
yield return "Name is required";

// Rich: provide structured information
yield return new ValidationError("API key format is invalid")
{
    PropertyName = nameof(ApiKey),
    ErrorCode = "API_KEY_FORMAT",
    Severity = ValidationSeverity.Error
};

// Warning (won't fail startup)
yield return new ValidationError("Timeout is unusually high")
{
    PropertyName = nameof(Timeout),
    Severity = ValidationSeverity.Warning
};

Remarks

This class provides rich validation error information including the property name, error code, and severity level. For simple cases, strings can be implicitly converted to ValidationError via the implicit operator.

Constructors

ValidationError(string) Constructor

Initializes a new instance of ValidationError with the specified message.

public ValidationError(string message);

Parameters

message System.String

The error message.

Properties

ValidationError.ErrorCode Property

Gets or sets an error code for programmatic handling or localization.

public string? ErrorCode { get; set; }

Property Value

System.String

ValidationError.Message Property

Gets the error message.

public string Message { get; }

Property Value

System.String

ValidationError.PropertyName Property

Gets or sets the name of the property that failed validation, if applicable.

public string? PropertyName { get; set; }

Property Value

System.String

ValidationError.Severity Property

Gets or sets the severity of the validation error. Only Error will cause startup to fail.

public NexusLabs.Needlr.Generators.ValidationSeverity Severity { get; set; }

Property Value

ValidationSeverity

Methods

ValidationError.Equals(object) Method

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj);

Parameters

obj System.Object

Returns

System.Boolean

ValidationError.GetHashCode() Method

Returns the hash code for this validation error.

public override int GetHashCode();

Returns

System.Int32

ValidationError.ToString() Method

Returns the error message, optionally prefixed with the property name.

public override string ToString();

Returns

System.String

Operators

ValidationError.implicit operator ValidationError(string) Operator

Implicitly converts a string to a ValidationError.

public static NexusLabs.Needlr.Generators.ValidationError implicit operator NexusLabs.Needlr.Generators.ValidationError(string message);

Parameters

message System.String

The error message.

Returns

ValidationError
A new ValidationError with the specified message.