Skip to content

Commit

Permalink
feat(BootstrapInputNumber): support NumberDecimalSeparator setting (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
densen2014 and ArgoZhang authored Dec 29, 2024
1 parent cc675fc commit da5fde6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public static string ConvertToPercentString(this string? val)
/// <returns></returns>
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);
Expand Down
12 changes: 12 additions & 0 deletions test/UnitTest/Extensions/ObjectExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit da5fde6

Please sign in to comment.