Skip to content

Commit 79a6dde

Browse files
committed
feat: 增加 ShouldRenderInputNumber 扩展方法
1 parent 47d2463 commit 79a6dde

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/BootstrapBlazor/Extensions/ObjectExtensions.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,24 @@ 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;
53+
var targetType = Nullable.GetUnderlyingType(t) ?? t;
54+
return targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) ||
55+
targetType == typeof(float) || targetType == typeof(double) || targetType == typeof(decimal);
56+
}
57+
58+
/// <summary>
59+
/// 检查是否应该渲染成 <see cref="BootstrapInputNumber{TValue}"/>
60+
/// </summary>
61+
/// <param name="t"></param>
62+
/// <returns></returns>
63+
public static bool ShouldRenderInputNumber(this Type t)
64+
{
65+
var separator = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
5466
if (separator != ".")
5567
{
5668
return false;
5769
}
58-
59-
var targetType = Nullable.GetUnderlyingType(t) ?? t;
60-
return targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) ||
61-
targetType == typeof(float) || targetType == typeof(double) || targetType == typeof(decimal);
70+
return t.IsNumber();
6271
}
6372

6473
/// <summary>

src/BootstrapBlazor/Utils/Utility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ private static Type GenerateComponentType(IEditorItem item)
638638
{
639639
ret = typeof(NullSwitch);
640640
}
641-
else if (fieldType.IsNumber())
641+
else if (fieldType.ShouldRenderInputNumber())
642642
{
643643
ret = typeof(BootstrapInputNumber<>).MakeGenericType(fieldType);
644644
}
@@ -704,7 +704,7 @@ private static Dictionary<string, object> CreateMultipleAttributes(Type fieldTyp
704704
ret.Add("rows", item.Rows);
705705
}
706706
}
707-
else if (type.IsNumber())
707+
else if (type.ShouldRenderInputNumber())
708708
{
709709
if (!string.IsNullOrEmpty(item.Step))
710710
{

0 commit comments

Comments
 (0)