namespace ADOFAIRenderer.Data { /// /// Base class for double input validation limits. /// Multiple limits can be composed on a single input field — all are checked in order. /// internal abstract class DoubleLimit { /// /// Validates the given double value against this limit. /// /// The parsed double value to validate. /// /// When validation fails, set to a human-readable error message. /// When validation succeeds, set to null. /// /// true if the value satisfies this limit; false otherwise. public abstract bool Validate(double value, out string errorMessage); } /// /// Requires the double value to be strictly positive (> 0). /// internal class PositiveOnlyDoubleLimit : DoubleLimit { public override bool Validate(double value, out string errorMessage) { if (value > 0) { errorMessage = null!; return true; } errorMessage = "값은 0보다 큰 양수여야 합니다."; return false; } } /// /// Requires the double value to be within an inclusive [Min, Max] range. /// Either bound can be null to represent an unbounded side. /// internal class RangeDoubleLimit : DoubleLimit { public double? Min { get; } public double? Max { get; } /// Inclusive lower bound, or null for no lower bound. /// Inclusive upper bound, or null for no upper bound. public RangeDoubleLimit(double? min, double? max) { Min = min; Max = max; } public override bool Validate(double value, out string errorMessage) { if (Min.HasValue && value < Min.Value) { errorMessage = Max.HasValue ? $"값은 {Min.Value}에서 {Max.Value} 사이의 숫자여야 합니다." : $"값은 {Min.Value} 이상의 숫자여야 합니다."; return false; } if (Max.HasValue && value > Max.Value) { errorMessage = Min.HasValue ? $"값은 {Min.Value}에서 {Max.Value} 사이의 숫자여야 합니다." : $"값은 {Max.Value} 이하의 숫자여야 합니다."; return false; } errorMessage = null!; return true; } } }