From ff7bbad5b928ca00c2637e6d8ec50453a1a80891 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 5 Apr 2024 20:39:13 +0800 Subject: [PATCH] fix #188 if bigger the Max set max if less then Min, ser min --- src/Ursa/Controls/NumericUpDown/IntUpDown.cs | 84 ++++++++++++++++---- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/src/Ursa/Controls/NumericUpDown/IntUpDown.cs b/src/Ursa/Controls/NumericUpDown/IntUpDown.cs index eabbe4a..655a7b1 100644 --- a/src/Ursa/Controls/NumericUpDown/IntUpDown.cs +++ b/src/Ursa/Controls/NumericUpDown/IntUpDown.cs @@ -25,9 +25,17 @@ public class NumericIntUpDown : NumericUpDownBase protected override int Zero => 0; - protected override int? Add(int? a, int? b) => a + b; + protected override int? Add(int? a, int? b) + { + var result = a + b; + return result < Value ? Maximum : result; + } - protected override int? Minus(int? a, int? b) => a - b; + protected override int? Minus(int? a, int? b) + { + var result = a - b; + return result > Value ? Minimum : result; + } } public class NumericUIntUpDown : NumericUpDownBase @@ -53,9 +61,17 @@ public class NumericUIntUpDown : NumericUpDownBase protected override uint Zero => 0; - protected override uint? Add(uint? a, uint? b) => a + b; + protected override uint? Add(uint? a, uint? b) + { + var result = a + b; + return result < Value ? Maximum : result; + } - protected override uint? Minus(uint? a, uint? b) => a - b; + protected override uint? Minus(uint? a, uint? b) + { + var result = a - b; + return result > Value ? Minimum : result; + } } public class NumericDoubleUpDown : NumericUpDownBase @@ -99,9 +115,17 @@ public class NumericByteUpDown : NumericUpDownBase protected override byte Zero => 0; - protected override byte? Add(byte? a, byte? b) => (byte?)(a + b); + protected override byte? Add(byte? a, byte? b) + { + var result = a + b; + return (byte?)(result < Value ? Maximum : result); + } - protected override byte? Minus(byte? a, byte? b) => (byte?)(a - b); + protected override byte? Minus(byte? a, byte? b) + { + var result = a - b; + return (byte?)(result > Value ? Minimum : result); + } } public class NumericSByteUpDown : NumericUpDownBase @@ -122,9 +146,17 @@ public class NumericSByteUpDown : NumericUpDownBase protected override sbyte Zero => 0; - protected override sbyte? Add(sbyte? a, sbyte? b) => (sbyte?)(a + b); + protected override sbyte? Add(sbyte? a, sbyte? b) + { + var result = a + b; + return (sbyte?)(result < Value ? Maximum : result); + } - protected override sbyte? Minus(sbyte? a, sbyte? b) => (sbyte?)(a - b); + protected override sbyte? Minus(sbyte? a, sbyte? b) + { + var result = a - b; + return (sbyte?)(result > Value ? Minimum : result); + } } public class NumericShortUpDown : NumericUpDownBase @@ -145,9 +177,17 @@ public class NumericShortUpDown : NumericUpDownBase protected override short Zero => 0; - protected override short? Add(short? a, short? b) => (short?)(a + b); + protected override short? Add(short? a, short? b) + { + var result = a + b; + return (short?)(result < Value ? Maximum : result); + } - protected override short? Minus(short? a, short? b) => (short?)(a - b); + protected override short? Minus(short? a, short? b) + { + var result = a - b; + return (short?)(result > Value ? Minimum : result); + } } public class NumericUShortUpDown : NumericUpDownBase @@ -168,9 +208,17 @@ public class NumericUShortUpDown : NumericUpDownBase protected override ushort Zero => 0; - protected override ushort? Add(ushort? a, ushort? b) => (ushort?)(a + b); + protected override ushort? Add(ushort? a, ushort? b) + { + var result = a + b; + return (ushort?)(result < Value ? Maximum : result); + } - protected override ushort? Minus(ushort? a, ushort? b) => (ushort?)(a - b); + protected override ushort? Minus(ushort? a, ushort? b) + { + var result = a - b; + return (ushort?)(result > Value ? Minimum : result); + } } public class NumericLongUpDown : NumericUpDownBase @@ -191,9 +239,17 @@ public class NumericLongUpDown : NumericUpDownBase protected override long Zero => 0; - protected override long? Add(long? a, long? b) => a + b; + protected override long? Add(long? a, long? b) + { + var result = a + b; + return result < Value ? Maximum : result; + } - protected override long? Minus(long? a, long? b) => a - b; + protected override long? Minus(long? a, long? b) + { + var result = a - b; + return result > Value ? Minimum : result; + } } public class NumericULongUpDown : NumericUpDownBase