Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading