ValidationError
NexusLabs.Needlr.Generators¶
ValidationError Class¶
Represents a validation error with optional structured information.
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.
Parameters¶
message System.String
The error message.
Properties¶
ValidationError.ErrorCode Property¶
Gets or sets an error code for programmatic handling or localization.
Property Value¶
ValidationError.Message Property¶
Gets the error message.
Property Value¶
ValidationError.PropertyName Property¶
Gets or sets the name of the property that failed validation, if applicable.
Property Value¶
ValidationError.Severity Property¶
Gets or sets the severity of the validation error. Only Error will cause startup to fail.
Property Value¶
Methods¶
ValidationError.Equals(object) Method¶
Determines whether the specified object is equal to the current object.
Parameters¶
obj System.Object
Returns¶
ValidationError.GetHashCode() Method¶
Returns the hash code for this validation error.
Returns¶
ValidationError.ToString() Method¶
Returns the error message, optionally prefixed with the property name.
Returns¶
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.