From da5fde6b141348e0272abf449a0c0605106885b1 Mon Sep 17 00:00:00 2001 From: Alex chow Date: Sun, 29 Dec 2024 05:12:14 +0100 Subject: [PATCH] feat(BootstrapInputNumber): support NumberDecimalSeparator setting (#4983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(GenerateComponentType)#4982-Numeric-type-rendered * Revert "feat(GenerateComponentType)#4982-Numeric-type-rendered" This reverts commit 7309a0569fb25bf45d3cccd6273f57a3ef3f2a35. * feat(GenerateComponentType)#4982-Numeric-type-rendered * refactor: 移动扩展方法 * test: 增加单元测试 --------- Co-Authored-By: Argo Zhang --- src/BootstrapBlazor/Extensions/ObjectExtensions.cs | 6 ++++++ test/UnitTest/Extensions/ObjectExtensionsTest.cs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs index bf1a3f5691e..2398cf9e657 100644 --- a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs @@ -50,6 +50,12 @@ public static string ConvertToPercentString(this string? val) /// public static bool IsNumber(this Type t) { + var separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; + if (separator != ".") + { + return false; + } + var targetType = Nullable.GetUnderlyingType(t) ?? t; return targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) || targetType == typeof(float) || targetType == typeof(double) || targetType == typeof(decimal); diff --git a/test/UnitTest/Extensions/ObjectExtensionsTest.cs b/test/UnitTest/Extensions/ObjectExtensionsTest.cs index dba024c88b5..4dd96a23e3a 100644 --- a/test/UnitTest/Extensions/ObjectExtensionsTest.cs +++ b/test/UnitTest/Extensions/ObjectExtensionsTest.cs @@ -44,6 +44,18 @@ public static void IsNumber_Ok(Type source, bool expect) Assert.Equal(expect, actual); } + [Fact] + public void IsNumber_Culture() + { + var culture = new CultureInfo("es-ES"); + CultureInfo.CurrentCulture = culture; + Assert.False(typeof(long).IsNumber()); + + culture = new CultureInfo("en-US"); + CultureInfo.CurrentCulture = culture; + Assert.True(typeof(long).IsNumber()); + } + [Theory] [InlineData(typeof(DateTime?), true)] [InlineData(typeof(DateTime), true)]