Skip to content

Commit da5fde6

Browse files
feat(BootstrapInputNumber): support NumberDecimalSeparator setting (#4983)
* feat(GenerateComponentType)#4982-Numeric-type-rendered * Revert "feat(GenerateComponentType)#4982-Numeric-type-rendered" This reverts commit 7309a05. * feat(GenerateComponentType)#4982-Numeric-type-rendered * refactor: 移动扩展方法 * test: 增加单元测试 --------- Co-Authored-By: Argo Zhang <[email protected]>
1 parent cc675fc commit da5fde6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/BootstrapBlazor/Extensions/ObjectExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public static string ConvertToPercentString(this string? val)
5050
/// <returns></returns>
5151
public static bool IsNumber(this Type t)
5252
{
53+
var separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
54+
if (separator != ".")
55+
{
56+
return false;
57+
}
58+
5359
var targetType = Nullable.GetUnderlyingType(t) ?? t;
5460
return targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) ||
5561
targetType == typeof(float) || targetType == typeof(double) || targetType == typeof(decimal);

test/UnitTest/Extensions/ObjectExtensionsTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public static void IsNumber_Ok(Type source, bool expect)
4444
Assert.Equal(expect, actual);
4545
}
4646

47+
[Fact]
48+
public void IsNumber_Culture()
49+
{
50+
var culture = new CultureInfo("es-ES");
51+
CultureInfo.CurrentCulture = culture;
52+
Assert.False(typeof(long).IsNumber());
53+
54+
culture = new CultureInfo("en-US");
55+
CultureInfo.CurrentCulture = culture;
56+
Assert.True(typeof(long).IsNumber());
57+
}
58+
4759
[Theory]
4860
[InlineData(typeof(DateTime?), true)]
4961
[InlineData(typeof(DateTime), true)]

0 commit comments

Comments
 (0)