namespace StellaOps.DependencyInjection.Validation; public abstract partial class OptionsValidatorBase where TOptions : class { /// /// Provides a fluent interface for collecting validation errors. /// protected sealed partial class ValidationContext { private readonly List _errors = new(); private readonly string _sectionPrefix; internal ValidationContext(string sectionPrefix) { _sectionPrefix = sectionPrefix; } /// /// Gets the collected errors. /// public IReadOnlyList Errors => _errors; /// /// Returns true if any errors have been added. /// public bool HasErrors => _errors.Count > 0; /// /// Adds a validation error for a specific property. /// /// The property name (e.g., "MaxRetries"). /// The error message. /// This context for chaining. public ValidationContext AddError(string propertyName, string message) { _errors.Add($"{_sectionPrefix}:{propertyName} {message}"); return this; } /// /// Adds a validation error for a nested property. /// /// The parent property name. /// The child property name. /// The error message. /// This context for chaining. public ValidationContext AddError(string parentProperty, string childProperty, string message) { _errors.Add($"{_sectionPrefix}:{parentProperty}:{childProperty} {message}"); return this; } /// /// Adds a general validation error. /// /// The error message. /// This context for chaining. public ValidationContext AddGeneralError(string message) { _errors.Add($"{_sectionPrefix}: {message}"); return this; } /// /// Conditionally adds an error if the condition is true. /// /// The condition to check. /// The property name. /// The error message. /// This context for chaining. public ValidationContext AddErrorIf(bool condition, string propertyName, string message) { if (condition) { AddError(propertyName, message); } return this; } } }