Skip to content

Commit 3c7760f

Browse files
committed
Merge remote-tracking branch 'origin/refactor-input' into refactor-export
2 parents 5f51098 + be84586 commit 3c7760f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
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 IsNumberWithDotSeparator(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.IsNumberWithDotSeparator())
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.IsNumberWithDotSeparator())
708708
{
709709
if (!string.IsNullOrEmpty(item.Step))
710710
{

test/UnitTest/Extensions/ObjectExtensionsTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ public void IsNumber_Culture()
4949
{
5050
var culture = new CultureInfo("es-ES");
5151
CultureInfo.CurrentCulture = culture;
52-
Assert.False(typeof(long).IsNumber());
52+
Assert.True(typeof(long).IsNumber());
53+
Assert.False(typeof(long).IsNumberWithDotSeparator());
5354

5455
culture = new CultureInfo("en-US");
5556
CultureInfo.CurrentCulture = culture;
5657
Assert.True(typeof(long).IsNumber());
58+
Assert.True(typeof(long).IsNumberWithDotSeparator());
5759
}
5860

5961
[Theory]

0 commit comments

Comments
 (0)