diff --git a/src/MatBlazor/Components/MatNumericUpDownField/BaseMatNumericUpDownFieldInternal.cs b/src/MatBlazor/Components/MatNumericUpDownField/BaseMatNumericUpDownFieldInternal.cs index 0503c99e..5ea7f9f8 100644 --- a/src/MatBlazor/Components/MatNumericUpDownField/BaseMatNumericUpDownFieldInternal.cs +++ b/src/MatBlazor/Components/MatNumericUpDownField/BaseMatNumericUpDownFieldInternal.cs @@ -19,12 +19,14 @@ protected override EventCallback OnKeyDownEvent() protected void Increase() { - CurrentValue = SwitchT.Increase(CurrentValue, Step, Maximum); + CurrentValue = SwitchT.Increase(CurrentValue, Step); + CurrentValue = SwitchT.Clamp(CurrentValue, Minimum, Maximum); } protected void Decrease() { - CurrentValue = SwitchT.Decrease(CurrentValue, Step, Minimum); + CurrentValue = SwitchT.Decrease(CurrentValue, Step); + CurrentValue = SwitchT.Clamp(CurrentValue, Minimum, Maximum); } protected override TValue CurrentValue @@ -66,6 +68,8 @@ protected override bool InputTextReadOnly() private readonly EventCallback OnKeyDownEvent2; public BaseMatNumericUpDownFieldInternal() { + OnFocusOutEvent.Event += OnFocusOutEvent_Event; + OnKeyDownEvent2 = EventCallback.Factory.Create(this, async (e) => { await OnKeyDown.InvokeAsync(e); @@ -78,13 +82,20 @@ public BaseMatNumericUpDownFieldInternal() Decrease(); } }); - Maximum = SwitchT.GetMaximum(); - Minimum = SwitchT.GetMinimum(); + + Maximum ??= SwitchT.GetMaximum(); + Minimum ??= SwitchT.GetMinimum(); ClassMapper.Add("mat-numeric-up-down-field"); ClassMapper.Add("mat-text-field-with-actions-container"); } + private void OnFocusOutEvent_Event(object sender, FocusEventArgs e) + { + // Clamp to minimum and maximum on blur. + CurrentValue = SwitchT.Clamp(CurrentValue, Minimum, Maximum); + } + private readonly TValue ZeroValue = MatTypeConverter.ChangeType(0); protected override void OnParametersSet() @@ -107,7 +118,10 @@ protected override void OnParametersSet() } else { - Step = SwitchT.GetStep(); + if (Step == null || Step.Equals(ZeroValue)) + { + Step = SwitchT.GetStep(); + } } } diff --git a/src/MatBlazor/Components/MatPaginator/BaseMatPaginator.cs b/src/MatBlazor/Components/MatPaginator/BaseMatPaginator.cs index 567928f3..3d3bde5c 100644 --- a/src/MatBlazor/Components/MatPaginator/BaseMatPaginator.cs +++ b/src/MatBlazor/Components/MatPaginator/BaseMatPaginator.cs @@ -98,7 +98,7 @@ public async Task NavigateToPage(MatPaginatorAction direction, int pageSize) { page = ((PageIndex * PageSize) / pageSize); } - catch (OverflowException e) + catch (OverflowException) { } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchT.cs b/src/MatBlazor/Core/MatBlazorSwitchT.cs index 667721b9..e98ba023 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchT.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchT.cs @@ -8,8 +8,9 @@ namespace MatBlazor { public abstract class MatBlazorSwitchT { - public abstract T Increase(T v, T step, T max); - public abstract T Decrease(T v, T step, T min); + public abstract T Clamp(T v, T min, T max); + public abstract T Increase(T v, T step); + public abstract T Decrease(T v, T step); public abstract T Round(T v, int dp); public abstract T GetMinimum(); diff --git a/src/MatBlazor/Core/MatBlazorSwitchTBool.cs b/src/MatBlazor/Core/MatBlazorSwitchTBool.cs index dd37beea..40dbc77b 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTBool.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTBool.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.SymbolStore; using System.Globalization; namespace MatBlazor @@ -15,12 +16,17 @@ public override bool ToBool(bool v) return v; } - public override bool Increase(bool v, bool step, bool max) + public override bool Clamp(bool v, bool min, bool max) + { + return v; + } + + public override bool Increase(bool v, bool step) { return !v; } - public override bool Decrease(bool v, bool step, bool min) + public override bool Decrease(bool v, bool step) { return !v; } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTBoolNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTBoolNull.cs index 729c588c..c96b87de 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTBoolNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTBoolNull.cs @@ -15,12 +15,17 @@ public override bool ToBool(bool? v) return v ?? false; } - public override bool? Increase(bool? v, bool? step, bool? max) + public override bool? Clamp(bool? v, bool? min, bool? max) + { + return v; + } + + public override bool? Increase(bool? v, bool? step) { return !(v ?? false); } - public override bool? Decrease(bool? v, bool? step, bool? min) + public override bool? Decrease(bool? v, bool? step) { return !(v ?? false); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTByte.cs b/src/MatBlazor/Core/MatBlazorSwitchTByte.cs index b435358c..c542abf5 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTByte.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTByte.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTByte : MatBlazorSwitchT { - public override byte Increase(byte v, byte step, byte max) + public override byte Clamp(byte v, byte min, byte max) + { + return v < min ? min : v > max ? max : v; + } + + public override byte Increase(byte v, byte step) { checked { try { - var v2 = (byte) (v + step); - return v2 <= max ? v2 : max; + return (byte) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return byte.MaxValue; } } } - public override byte Decrease(byte v, byte step, byte min) + public override byte Decrease(byte v, byte step) { checked { try { - var v2 = (byte)(v - step); - return v2 >= min ? v2 : min; + return (byte)(v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return byte.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs index 7c26dd69..3b164f2a 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTByteNull : MatBlazorSwitchT { - public override byte? Increase(byte? v, byte? step, byte? max) + public override byte? Clamp(byte? v, byte? min, byte? max) + { + return v < min ? min : v > max ? max : v; + } + + public override byte? Increase(byte? v, byte? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) + (step ?? 0)) : null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) + (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return byte.MaxValue; } } } - public override byte? Decrease(byte? v, byte? step, byte? min) + public override byte? Decrease(byte? v, byte? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) - (step ?? 0)) : null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) - (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return byte.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTChar.cs b/src/MatBlazor/Core/MatBlazorSwitchTChar.cs index 6e4432d3..c2090105 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTChar.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTChar.cs @@ -4,34 +4,37 @@ namespace MatBlazor { public class MatBlazorSwitchTChar : MatBlazorSwitchT { - public override char Increase(char v, char step, char max) + public override char Clamp(char v, char min, char max) + { + return v < min ? min : v > max ? max : v; + } + + public override char Increase(char v, char step) { checked { try { - var v2 = (char) (v + step); - return v2 <= max ? v2 : max; + return (char) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return char.MaxValue; } } } - public override char Decrease(char v, char step, char min) + public override char Decrease(char v, char step) { checked { try { - var v2 = (char)(v - step); - return v2 >= min ? v2 : min; + return (char)(v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return char.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs index 736fa406..6cac467f 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs @@ -4,34 +4,37 @@ namespace MatBlazor { public class MatBlazorSwitchTCharNull : MatBlazorSwitchT { - public override char? Increase(char? v, char? step, char? max) + public override char? Clamp(char? v, char? min, char? max) + { + return v < min ? min : v > max ? max : v; + } + + public override char? Increase(char? v, char? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) + (step ?? 0)) : null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) + (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return char.MaxValue; } } } - public override char? Decrease(char? v, char? step, char? min) + public override char? Decrease(char? v, char? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) - (step ?? 0)) : null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) - (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return char.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTCommon.cs b/src/MatBlazor/Core/MatBlazorSwitchTCommon.cs index 25bb3c8e..a943c4ac 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTCommon.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTCommon.cs @@ -4,12 +4,17 @@ namespace MatBlazor { public class MatBlazorSwitchTCommon : MatBlazorSwitchT { - public override T Increase(T v, T step, T max) + public override T Clamp(T v, T min, T max) { throw new NotImplementedException(); } - public override T Decrease(T v, T step, T min) + public override T Increase(T v, T step) + { + throw new NotImplementedException(); + } + + public override T Decrease(T v, T step) { throw new NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDateTime.cs b/src/MatBlazor/Core/MatBlazorSwitchTDateTime.cs index 71e2c6f9..f141482b 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDateTime.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDateTime.cs @@ -5,12 +5,17 @@ namespace MatBlazor { public class MatBlazorSwitchTDateTime : MatBlazorSwitchT { - public override DateTime Increase(DateTime v, DateTime step, DateTime max) + public override DateTime Clamp(DateTime v, DateTime min, DateTime max) { throw new NotImplementedException(); } - public override DateTime Decrease(DateTime v, DateTime step, DateTime min) + public override DateTime Increase(DateTime v, DateTime step) + { + throw new NotImplementedException(); + } + + public override DateTime Decrease(DateTime v, DateTime step) { throw new NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDateTimeNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTDateTimeNull.cs index 3514ed77..cbe43a7d 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDateTimeNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDateTimeNull.cs @@ -5,12 +5,17 @@ namespace MatBlazor { public class MatBlazorSwitchTDateTimeNull : MatBlazorSwitchT { - public override DateTime? Increase(DateTime? v, DateTime? step, DateTime? max) + public override DateTime? Clamp(DateTime? v, DateTime? min, DateTime? max) { throw new NotImplementedException(); } - public override DateTime? Decrease(DateTime? v, DateTime? step, DateTime? min) + public override DateTime? Increase(DateTime? v, DateTime? step) + { + throw new NotImplementedException(); + } + + public override DateTime? Decrease(DateTime? v, DateTime? step) { throw new NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDecimal.cs b/src/MatBlazor/Core/MatBlazorSwitchTDecimal.cs index 99fcbc94..f38a13a7 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDecimal.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDecimal.cs @@ -8,34 +8,37 @@ namespace MatBlazor { public class MatBlazorSwitchTDecimal : MatBlazorSwitchT { - public override decimal Increase(decimal v, decimal step, decimal max) + public override decimal Clamp(decimal v, decimal min, decimal max) + { + return v < min ? min : v > max ? max : v; + } + + public override decimal Increase(decimal v, decimal step) { checked { try { - var v2 = (decimal) (v + step); - return v2 <= max ? v2 : max; + return (decimal) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return decimal.MaxValue; } } } - public override decimal Decrease(decimal v, decimal step, decimal min) + public override decimal Decrease(decimal v, decimal step) { checked { try { - var v2 = (decimal) (v - step); - return v2 >= min ? v2 : min; + return (decimal) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return decimal.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDecimalNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTDecimalNull.cs index 328bccf4..fdf6cec1 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDecimalNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDecimalNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTDecimalNull : MatBlazorSwitchT { - public override decimal? Increase(decimal? v, decimal? step, decimal? max) + public override decimal? Clamp(decimal? v, decimal? min, decimal? max) + { + return v < min ? min : v > max ? max : v; + } + + public override decimal? Increase(decimal? v, decimal? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (decimal?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (decimal?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return decimal.MaxValue; } } } - public override decimal? Decrease(decimal? v, decimal? step, decimal? min) + public override decimal? Decrease(decimal? v, decimal? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (decimal?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (decimal?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return decimal.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDouble.cs b/src/MatBlazor/Core/MatBlazorSwitchTDouble.cs index a667ae2f..143fafed 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDouble.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDouble.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTDouble : MatBlazorSwitchT { - public override double Increase(double v, double step, double max) + public override double Clamp(double v, double min, double max) + { + return v < min ? min : v > max ? max : v; + } + + public override double Increase(double v, double step) { checked { try { - var v2 = (double) (v + step); - return v2 <= max ? v2 : max; + return (double) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return double.MaxValue; } } } - public override double Decrease(double v, double step, double min) + public override double Decrease(double v, double step) { checked { try { - var v2 = (double) (v - step); - return v2 >= min ? v2 : min; + return (double) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return Double.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs index 999b7b49..72e45a52 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTDoubleNull : MatBlazorSwitchT { - public override double? Increase(double? v, double? step, double? max) + public override double? Clamp(double? v, double? min, double? max) + { + return v < min ? min : v > max ? max : v; + } + + public override double? Increase(double? v, double? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (double?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (double?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return double.MaxValue; } } } - public override double? Decrease(double? v, double? step, double? min) + public override double? Decrease(double? v, double? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (double?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (double?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return double.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTFloat.cs b/src/MatBlazor/Core/MatBlazorSwitchTFloat.cs index 04bbead8..69668de4 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTFloat.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTFloat.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTFloat : MatBlazorSwitchT { - public override float Increase(float v, float step, float max) + public override float Clamp(float v, float min, float max) + { + return v < min ? min : v > max ? max : v; + } + + public override float Increase(float v, float step) { checked { try { - var v2 = (float) (v + step); - return v2 <= max ? v2 : max; + return (float) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return float.MaxValue; } } } - public override float Decrease(float v, float step, float min) + public override float Decrease(float v, float step) { checked { try { - var v2 = (float)(v - step); - return v2 >= min ? v2 : min; + return (float)(v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return float.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs index 53bc4c0a..d6c1eb3a 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTFloatNull : MatBlazorSwitchT { - public override float? Increase(float? v, float? step, float? max) + public override float? Clamp(float? v, float? min, float? max) + { + return v < min ? min : v > max ? max : v; + } + + public override float? Increase(float? v, float? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (float?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (float?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return float.MaxValue; } } } - public override float? Decrease(float? v, float? step, float? min) + public override float? Decrease(float? v, float? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (float?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (float?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return float.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTGuid.cs b/src/MatBlazor/Core/MatBlazorSwitchTGuid.cs index 1e2382ed..71317dd9 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTGuid.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTGuid.cs @@ -4,12 +4,17 @@ namespace MatBlazor { public class MatBlazorSwitchTGuid : MatBlazorSwitchT { - public override Guid Increase(Guid v, Guid step, Guid max) + public override Guid Clamp(Guid v, Guid min, Guid max) { throw new NotImplementedException(); } - public override Guid Decrease(Guid v, Guid step, Guid min) + public override Guid Increase(Guid v, Guid step) + { + throw new NotImplementedException(); + } + + public override Guid Decrease(Guid v, Guid step) { throw new NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTGuidNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTGuidNull.cs index aa33d2ef..94cdb1a9 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTGuidNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTGuidNull.cs @@ -4,12 +4,17 @@ namespace MatBlazor { public class MatBlazorSwitchTGuidNull : MatBlazorSwitchT { - public override Guid? Increase(Guid? v, Guid? step, Guid? max) + public override Guid? Clamp(Guid? v, Guid? min, Guid? max) { throw new NotImplementedException(); } - public override Guid? Decrease(Guid? v, Guid? step, Guid? min) + public override Guid? Increase(Guid? v, Guid? step) + { + throw new NotImplementedException(); + } + + public override Guid? Decrease(Guid? v, Guid? step) { throw new NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTInt.cs b/src/MatBlazor/Core/MatBlazorSwitchTInt.cs index cd1e9368..134e7e57 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTInt.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTInt.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTInt : MatBlazorSwitchT { - public override int Increase(int v, int step, int max) + public override int Clamp(int v, int min, int max) + { + return v < min ? min : v > max ? max : v; + } + + public override int Increase(int v, int step) { checked { try { - var v2 = (int) (v + step); - return v2 <= max ? v2 : max; + return (int) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return int.MaxValue; } } } - public override int Decrease(int v, int step, int min) + public override int Decrease(int v, int step) { checked { try { - var v2 = (int) (v - step); - return v2 >= min ? v2 : min; + return (int) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return int.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs index 558025df..21f1e04e 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTIntNull : MatBlazorSwitchT { - public override int? Increase(int? v, int? step, int? max) + public override int? Clamp(int? v, int? min, int? max) + { + return v < min ? min : v > max ? max : v; + } + + public override int? Increase(int? v, int? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (int?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (int?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return int.MaxValue; } } } - public override int? Decrease(int? v, int? step, int? min) + public override int? Decrease(int? v, int? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (int?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (int?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return int.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTLong.cs b/src/MatBlazor/Core/MatBlazorSwitchTLong.cs index 45ec67d3..8f7f191f 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTLong.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTLong.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTLong : MatBlazorSwitchT { - public override long Increase(long v, long step, long max) + public override long Clamp(long v, long min, long max) + { + return v < min ? min : v > max ? max : v; + } + + public override long Increase(long v, long step) { checked { try { - var v2 = (long) (v + step); - return v2 <= max ? v2 : max; + return (long) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return long.MaxValue; } } } - public override long Decrease(long v, long step, long min) + public override long Decrease(long v, long step) { checked { try { - var v2 = (long) (v - step); - return v2 >= min ? v2 : min; + return (long) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return long.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs index bf8dacfd..bc7b5a82 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTLongNull : MatBlazorSwitchT { - public override long? Increase(long? v, long? step, long? max) + public override long? Clamp(long? v, long? min, long? max) + { + return v < min ? min : v > max ? max : v; + } + + public override long? Increase(long? v, long? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (long?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (long?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return long.MaxValue; } } } - public override long? Decrease(long? v, long? step, long? min) + public override long? Decrease(long? v, long? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (long?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (long?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return long.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTSByte.cs b/src/MatBlazor/Core/MatBlazorSwitchTSByte.cs index 19fbc370..e786d888 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTSByte.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTSByte.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTSByte : MatBlazorSwitchT { - public override sbyte Increase(sbyte v, sbyte step, sbyte max) + public override sbyte Clamp(sbyte v, sbyte min, sbyte max) + { + return v < min ? min : v > max ? max : v; + } + + public override sbyte Increase(sbyte v, sbyte step) { checked { try { - var v2 = (sbyte) (v + step); - return v2 <= max ? v2 : max; + return (sbyte) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return sbyte.MaxValue; } } } - public override sbyte Decrease(sbyte v, sbyte step, sbyte min) + public override sbyte Decrease(sbyte v, sbyte step) { checked { try { - var v2 = (sbyte) (v - step); - return v2 >= min ? v2 : min; + return (sbyte) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return sbyte.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs index 474de964..2fe308a1 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTSByteNull : MatBlazorSwitchT { - public override sbyte? Increase(sbyte? v, sbyte? step, sbyte? max) + public override sbyte? Clamp(sbyte? v, sbyte? min, sbyte? max) + { + return v < min ? min : v > max ? max : v; + } + + public override sbyte? Increase(sbyte? v, sbyte? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) + (step ?? 0)) : null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) + (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return sbyte.MaxValue; } } } - public override sbyte? Decrease(sbyte? v, sbyte? step, sbyte? min) + public override sbyte? Decrease(sbyte? v, sbyte? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) - (step ?? 0)) : null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) - (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return sbyte.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTShort.cs b/src/MatBlazor/Core/MatBlazorSwitchTShort.cs index 76e4e5b8..f9776c84 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTShort.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTShort.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTShort : MatBlazorSwitchT { - public override short Increase(short v, short step, short max) + public override short Clamp(short v, short min, short max) + { + return v < min ? min : v > max ? max : v; + } + + public override short Increase(short v, short step) { checked { try { - var v2 = (short) (v + step); - return v2 <= max ? v2 : max; + return (short) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return short.MaxValue; } } } - public override short Decrease(short v, short step, short min) + public override short Decrease(short v, short step) { checked { try { - var v2 = (short) (v - step); - return v2 >= min ? v2 : min; + return (short) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return short.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs index d74d5ae2..b15ab1aa 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTShortNull : MatBlazorSwitchT { - public override short? Increase(short? v, short? step, short? max) + public override short? Clamp(short? v, short? min, short? max) + { + return v < min ? min : v > max ? max : v; + } + + public override short? Increase(short? v, short? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) + (step ?? 0)) : null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) + (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return short.MaxValue; } } } - public override short? Decrease(short? v, short? step, short? min) + public override short? Decrease(short? v, short? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) - (step ?? 0)) : null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) - (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return short.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTString.cs b/src/MatBlazor/Core/MatBlazorSwitchTString.cs index f3352560..0f6a226a 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTString.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTString.cs @@ -4,12 +4,17 @@ namespace MatBlazor { public class MatBlazorSwitchTString : MatBlazorSwitchT { - public override string Increase(string v, string step, string max) + public override string Clamp(string v, string min, string max) { throw new System.NotImplementedException(); } - public override string Decrease(string v, string step, string min) + public override string Increase(string v, string step) + { + throw new System.NotImplementedException(); + } + + public override string Decrease(string v, string step) { throw new System.NotImplementedException(); } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUInt.cs b/src/MatBlazor/Core/MatBlazorSwitchTUInt.cs index e0381941..d570a184 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTUInt.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTUInt.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTUInt : MatBlazorSwitchT { - public override uint Increase(uint v, uint step, uint max) + public override uint Clamp(uint v, uint min, uint max) + { + return v < min ? min : v > max ? max : v; + } + + public override uint Increase(uint v, uint step) { checked { try { - var v2 = (uint) (v + step); - return v2 <= max ? v2 : max; + return (uint) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return uint.MaxValue; } } } - public override uint Decrease(uint v, uint step, uint min) + public override uint Decrease(uint v, uint step) { checked { try { - var v2 = (uint) (v - step); - return v2 >= min ? v2 : min; + return (uint) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return uint.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs index 8bd9ed1b..f045f581 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTUIntNull : MatBlazorSwitchT { - public override uint? Increase(uint? v, uint? step, uint? max) + public override uint? Clamp(uint? v, uint? min, uint? max) + { + return v < min ? min : v > max ? max : v; + } + + public override uint? Increase(uint? v, uint? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (uint?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (uint?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return uint.MaxValue; } } } - public override uint? Decrease(uint? v, uint? step, uint? min) + public override uint? Decrease(uint? v, uint? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (uint?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (uint?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return uint.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTULong.cs b/src/MatBlazor/Core/MatBlazorSwitchTULong.cs index 12dc81d4..72a0df37 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTULong.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTULong.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTULong : MatBlazorSwitchT { - public override ulong Increase(ulong v, ulong step, ulong max) + public override ulong Clamp(ulong v, ulong min, ulong max) + { + return v < min ? min : v > max ? max : v; + } + + public override ulong Increase(ulong v, ulong step) { checked { try { - var v2 = (ulong) (v + step); - return v2 <= max ? v2 : max; + return (ulong) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return ulong.MaxValue; } } } - public override ulong Decrease(ulong v, ulong step, ulong min) + public override ulong Decrease(ulong v, ulong step) { checked { try { - var v2 = (ulong) (v - step); - return v2 >= min ? v2 : min; + return (ulong) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return ulong.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs index 55dd33d2..a40ebddd 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTULongNull : MatBlazorSwitchT { - public override ulong? Increase(ulong? v, ulong? step, ulong? max) + public override ulong? Clamp(ulong? v, ulong? min, ulong? max) + { + return v < min ? min : v > max ? max : v; + } + + public override ulong? Increase(ulong? v, ulong? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (ulong?) null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (ulong?) null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return ulong.MaxValue; } } } - public override ulong? Decrease(ulong? v, ulong? step, ulong? min) + public override ulong? Decrease(ulong? v, ulong? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (ulong?) null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (ulong?) null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return ulong.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUShort.cs b/src/MatBlazor/Core/MatBlazorSwitchTUShort.cs index e3e7da21..f20ecab6 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTUShort.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTUShort.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTUShort : MatBlazorSwitchT { - public override ushort Increase(ushort v, ushort step, ushort max) + public override ushort Clamp(ushort v, ushort min, ushort max) + { + return v < min ? min : v > max ? max : v; + } + + public override ushort Increase(ushort v, ushort step) { checked { try { - var v2 = (ushort) (v + step); - return v2 <= max ? v2 : max; + return (ushort) (v + step); } - catch (OverflowException e) + catch (OverflowException) { - return max; + return ushort.MaxValue; } } } - public override ushort Decrease(ushort v, ushort step, ushort min) + public override ushort Decrease(ushort v, ushort step) { checked { try { - var v2 = (ushort) (v - step); - return v2 >= min ? v2 : min; + return (ushort) (v - step); } - catch (OverflowException e) + catch (OverflowException) { - return min; + return ushort.MinValue; } } } diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs index 6178d165..7cfc6cac 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs @@ -5,34 +5,37 @@ namespace MatBlazor { public class MatBlazorSwitchTUShortNull : MatBlazorSwitchT { - public override ushort? Increase(ushort? v, ushort? step, ushort? max) + public override ushort? Clamp(ushort? v, ushort? min, ushort? max) + { + return v < min ? min : v > max ? max : v; + } + + public override ushort? Increase(ushort? v, ushort? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) + (step ?? 0)) : null; - return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + return (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) + (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return max; + return ushort.MaxValue; } } } - public override ushort? Decrease(ushort? v, ushort? step, ushort? min) + public override ushort? Decrease(ushort? v, ushort? step) { checked { try { - var v2 = (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) - (step ?? 0)) : null; - return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + return (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) - (step ?? 0)) : null; } - catch (OverflowException e) + catch (OverflowException) { - return min; + return ushort.MinValue; } } }