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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.2.3-beta01</Version>
<Version>9.2.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 14 additions & 5 deletions src/BootstrapBlazor/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,24 @@ public static string ConvertToPercentString(this string? val)
/// <returns></returns>
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);
}

/// <summary>
/// 检查是否应该渲染成 <see cref="BootstrapInputNumber{TValue}"/>
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
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();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Utils/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -704,7 +704,7 @@ private static Dictionary<string, object> CreateMultipleAttributes(Type fieldTyp
ret.Add("rows", item.Rows);
}
}
else if (type.IsNumber())
else if (type.IsNumberWithDotSeparator())
{
if (!string.IsNullOrEmpty(item.Step))
{
Expand Down
8 changes: 5 additions & 3 deletions test/UnitTest/Extensions/ObjectExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading