diff --git a/src/Beutl.Core/Validation/RangeDataAnnotationValidater.cs b/src/Beutl.Core/Validation/RangeDataAnnotationValidater.cs index 37b339b20..e4e19ca43 100644 --- a/src/Beutl.Core/Validation/RangeDataAnnotationValidater.cs +++ b/src/Beutl.Core/Validation/RangeDataAnnotationValidater.cs @@ -38,8 +38,27 @@ public RangeDataAnnotationValidater(RangeAttribute attribute) public override bool TryCoerce(ValidationContext context, ref TNumber value) { - value = TNumber.Clamp(value, Minimum, Maximum); - return true; + switch ((Attribute?.MaximumIsExclusive, Attribute?.MinimumIsExclusive)) + { + case (true, true): + return false; + + case (true, false): + value = TNumber.Max(value, Minimum); + return true; + + case (false, true): + value = TNumber.Min(value, Maximum); + return true; + + case (false, false): + value = TNumber.Clamp(value, Minimum, Maximum); + value = TNumber.Min(value, Maximum); + return true; + + default: + return false; + } } public override string? Validate(ValidationContext context, TNumber value) diff --git a/src/Beutl.Core/Validation/TupleRangeDataAnnotationValidater.cs b/src/Beutl.Core/Validation/TupleRangeDataAnnotationValidater.cs index b1c852b24..3d483d40b 100644 --- a/src/Beutl.Core/Validation/TupleRangeDataAnnotationValidater.cs +++ b/src/Beutl.Core/Validation/TupleRangeDataAnnotationValidater.cs @@ -10,6 +10,9 @@ public sealed class TupleRangeDataAnnotationValidater : RangeVa { public TupleRangeDataAnnotationValidater(RangeAttribute attribute) { + if (attribute.MaximumIsExclusive || attribute.MinimumIsExclusive) + throw new NotSupportedException("'MaximumIsExclusive' or 'MinimumIsExclusive' cannot be set to True."); + Attribute = attribute; if (Attribute.OperandType == typeof(TTuple) && Attribute.Maximum is string maximumStr