Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BootstrapInputNumber): throw exception when NumberDecimalSeparator is comma #5028

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 ShouldRenderInputNumber(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.ShouldRenderInputNumber())
{
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.ShouldRenderInputNumber())
{
if (!string.IsNullOrEmpty(item.Step))
{
Expand Down
Loading