From 55c3100e25a78444b6b89eba15bd6012bf1932d2 Mon Sep 17 00:00:00 2001 From: "daniele.corsini@corsinvest.it" Date: Tue, 2 Jul 2024 08:48:21 +0200 Subject: [PATCH 1/4] Add sbyte to number filed --- src/Core/Components/Base/InputHelpers.cs | 22 ++++++++++++++----- .../NumberField/FluentNumberField.razor.cs | 4 +++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Core/Components/Base/InputHelpers.cs b/src/Core/Components/Base/InputHelpers.cs index 2a5cc4158b..a2702b1f22 100644 --- a/src/Core/Components/Base/InputHelpers.cs +++ b/src/Core/Components/Base/InputHelpers.cs @@ -4,7 +4,6 @@ namespace Microsoft.FluentUI.AspNetCore.Components; internal static class InputHelpers { - public static string GetMaxValue() { Type? targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); @@ -51,9 +50,20 @@ public static string GetMinValue() return value; } - internal static void ValidateIntegerInputs(string? max, string? min) + + internal static void ValidateSByteInputs(string max, string min) { + var maxValue = Convert.ToSByte(max, CultureInfo.InvariantCulture); + var minValue = Convert.ToSByte(min, CultureInfo.InvariantCulture); + + if (maxValue < minValue) + { + throw new ArgumentException("Float Max value is smaller than Min value."); + } + } + internal static void ValidateIntegerInputs(string? max, string? min) + { var maxValue = Convert.ToInt32(max); var minValue = Convert.ToInt32(min); @@ -61,7 +71,6 @@ internal static void ValidateIntegerInputs(string? max, string? min) { throw new ArgumentException("Integer Max value is smaller then Min value."); } - } internal static void ValidateLongInputs(string? max, string? min) @@ -137,6 +146,11 @@ internal static void ValidateInputParameters(string? max, string? min) return; //nothing to validate } + if (typeof(TValue) == typeof(sbyte)) + { + ValidateSByteInputs(max, min); + } + if (typeof(TValue) == typeof(int)) { ValidateIntegerInputs(max, min); @@ -149,7 +163,6 @@ internal static void ValidateInputParameters(string? max, string? min) if (typeof(TValue) == typeof(short)) { - ValidateShortInputs(max, min); } @@ -165,7 +178,6 @@ internal static void ValidateInputParameters(string? max, string? min) if (typeof(TValue) == typeof(decimal)) { - ValidateDecimalInputs(max, min); } } diff --git a/src/Core/Components/NumberField/FluentNumberField.razor.cs b/src/Core/Components/NumberField/FluentNumberField.razor.cs index 021e92886b..0eb8a75287 100644 --- a/src/Core/Components/NumberField/FluentNumberField.razor.cs +++ b/src/Core/Components/NumberField/FluentNumberField.razor.cs @@ -79,7 +79,8 @@ private static string GetStepAttributeValue() // Unwrap Nullable, because InputBase already deals with the Nullable aspect // of it for us. We will only get asked to parse the T for nonempty inputs. var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); - if (targetType == typeof(int) || + if (targetType == typeof(sbyte) || + targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) || targetType == typeof(float) || @@ -119,6 +120,7 @@ protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(fa return value switch { null => null, + sbyte @sbyte => BindConverter.FormatValue(Convert.ToInt16(@sbyte), CultureInfo.InvariantCulture), int @int => BindConverter.FormatValue(@int, CultureInfo.InvariantCulture), long @long => BindConverter.FormatValue(@long, CultureInfo.InvariantCulture), short @short => BindConverter.FormatValue(@short, CultureInfo.InvariantCulture), From 8ecd66ee5d2c69088660473f92482ad303581e2a Mon Sep 17 00:00:00 2001 From: "daniele.corsini@corsinvest.it" Date: Tue, 2 Jul 2024 09:27:14 +0200 Subject: [PATCH 2/4] Fix error message --- src/Core/Components/Base/InputHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Components/Base/InputHelpers.cs b/src/Core/Components/Base/InputHelpers.cs index a2702b1f22..f003b0a2c3 100644 --- a/src/Core/Components/Base/InputHelpers.cs +++ b/src/Core/Components/Base/InputHelpers.cs @@ -58,7 +58,7 @@ internal static void ValidateSByteInputs(string max, string min) if (maxValue < minValue) { - throw new ArgumentException("Float Max value is smaller than Min value."); + throw new ArgumentException("Signed Integer Max value is smaller than Min value."); } } From 03a4827d8e5a69bceab92e2f94216034339ca455 Mon Sep 17 00:00:00 2001 From: "daniele.corsini@corsinvest.it" Date: Tue, 2 Jul 2024 09:32:11 +0200 Subject: [PATCH 3/4] Remove empy line --- src/Core/Components/Base/InputHelpers.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core/Components/Base/InputHelpers.cs b/src/Core/Components/Base/InputHelpers.cs index f003b0a2c3..41936cb3fd 100644 --- a/src/Core/Components/Base/InputHelpers.cs +++ b/src/Core/Components/Base/InputHelpers.cs @@ -50,7 +50,6 @@ public static string GetMinValue() return value; } - internal static void ValidateSByteInputs(string max, string min) { var maxValue = Convert.ToSByte(max, CultureInfo.InvariantCulture); From 04f7b2eb6a0239c38e1ac43c7d7de1b0f4f40f94 Mon Sep 17 00:00:00 2001 From: "daniele.corsini@corsinvest.it" Date: Tue, 2 Jul 2024 10:53:30 +0200 Subject: [PATCH 4/4] Fix converter --- src/Core/Components/Base/InputHelpers.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/Components/Base/InputHelpers.cs b/src/Core/Components/Base/InputHelpers.cs index 41936cb3fd..f4e7a186f9 100644 --- a/src/Core/Components/Base/InputHelpers.cs +++ b/src/Core/Components/Base/InputHelpers.cs @@ -50,10 +50,10 @@ public static string GetMinValue() return value; } - internal static void ValidateSByteInputs(string max, string min) + internal static void ValidateSByteInputs(string? max, string? min) { - var maxValue = Convert.ToSByte(max, CultureInfo.InvariantCulture); - var minValue = Convert.ToSByte(min, CultureInfo.InvariantCulture); + var maxValue = Convert.ToSByte(max); + var minValue = Convert.ToSByte(min); if (maxValue < minValue) {