diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 95b737a19f7..b48e196c1e5 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.2.3-beta01 + 9.2.3 diff --git a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs index 2398cf9e657..f5271bf5fd4 100644 --- a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs @@ -50,15 +50,24 @@ public static string ConvertToPercentString(this string? val) /// public static bool IsNumber(this Type t) { - var separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; + 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); + } + + /// + /// 检查是否应该渲染成 + /// + /// + /// + public static bool IsNumberWithDotSeparator(this Type t) + { + var separator = CultureInfo.CurrentUICulture.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); + return t.IsNumber(); } /// diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs index fac7cc9fed5..e8ff2771818 100644 --- a/src/BootstrapBlazor/Utils/Utility.cs +++ b/src/BootstrapBlazor/Utils/Utility.cs @@ -638,7 +638,7 @@ private static Type GenerateComponentType(IEditorItem item) { ret = typeof(NullSwitch); } - else if (fieldType.IsNumber()) + else if (fieldType.IsNumberWithDotSeparator()) { ret = typeof(BootstrapInputNumber<>).MakeGenericType(fieldType); } @@ -704,7 +704,7 @@ private static Dictionary CreateMultipleAttributes(Type fieldTyp ret.Add("rows", item.Rows); } } - else if (type.IsNumber()) + else if (type.IsNumberWithDotSeparator()) { if (!string.IsNullOrEmpty(item.Step)) { diff --git a/test/UnitTest/Extensions/ObjectExtensionsTest.cs b/test/UnitTest/Extensions/ObjectExtensionsTest.cs index 4dd96a23e3a..74d6aeded7f 100644 --- a/test/UnitTest/Extensions/ObjectExtensionsTest.cs +++ b/test/UnitTest/Extensions/ObjectExtensionsTest.cs @@ -48,12 +48,14 @@ public static void IsNumber_Ok(Type source, bool expect) public void IsNumber_Culture() { var culture = new CultureInfo("es-ES"); - CultureInfo.CurrentCulture = culture; - Assert.False(typeof(long).IsNumber()); + CultureInfo.CurrentUICulture = culture; + Assert.True(typeof(long).IsNumber()); + Assert.False(typeof(long).IsNumberWithDotSeparator()); culture = new CultureInfo("en-US"); - CultureInfo.CurrentCulture = culture; + CultureInfo.CurrentUICulture = culture; Assert.True(typeof(long).IsNumber()); + Assert.True(typeof(long).IsNumberWithDotSeparator()); } [Theory]