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
11 changes: 7 additions & 4 deletions src/BootstrapBlazor/Components/Display/DisplayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ public abstract class DisplayBase<TValue> : BootstrapModuleComponentBase
protected FieldIdentifier? FieldIdentifier { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 泛型参数 TValue 可为空类型 Type 实例,为空时表示类型不可为空</para>
/// <para lang="en">Gets or sets Generic Parameter TValue Nullable Type Instance. Null means type is not nullable</para>
/// <para lang="zh">获得 泛型参数 TValue 可为空类型 Type 实例,为空时表示类型不可为空</para>
/// <para lang="en">Gets the underlying type of <typeparamref name="TValue"/> when it is <see cref="Nullable{T}"/>; otherwise <see langword="null"/>.</para>
/// </summary>
Comment on lines 29 to 32
protected Type? NullableUnderlyingType { get; set; }
/// <remarks>
/// <para lang="zh">每个封闭泛型类型只计算一次缓存为静态字段,避免热路径重复反射</para>
/// <para lang="en">Cached once per closed generic type to avoid repeated reflection on hot paths.</para>
/// </remarks>
protected static readonly Type? NullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue));

/// <summary>
/// <para lang="zh">获得/设置 泛型参数 TValue 可为空类型 Type 实例</para>
Expand Down Expand Up @@ -121,7 +125,6 @@ public override Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);

NullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue));
ValueType ??= NullableUnderlyingType ?? typeof(TValue);

if (ValueExpression != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static TValue ParseValue(string value)
private bool IsDecimalType()
{
// 检查是否允许带小数点数据类型
var type = NullableUnderlyingType ?? typeof(TValue);
var type = ValueType;
return type == typeof(float) || type == typeof(double) || type == typeof(decimal);
}

Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Radio/RadioList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public partial class RadioList<TValue>
/// </summary>
protected override void OnParametersSet()
{
var t = NullableUnderlyingType ?? typeof(TValue);
var t = ValueType;
if (t.IsEnum && Items == null)
{
Items = t.ToSelectList((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem("", NullItemText) : null);
Expand Down Expand Up @@ -91,7 +91,7 @@ protected override void OnParametersSet()
protected override bool TryParseValueFromString(string value, [MaybeNullWhen(false)] out TValue result, out string? validationErrorMessage)
{
var ret = false;
var t = NullableUnderlyingType ?? typeof(TValue);
var t = ValueType;
result = default;
if (t == typeof(SelectedItem))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override void OnParametersSet()
Color = Color.Primary;
}

var t = NullableUnderlyingType ?? typeof(TValue);
var t = ValueType;
if (t.IsEnum && Items == null)
{
Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default!, NullItemText) : null);
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Select/MultiSelect.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private void ResetItems()
}
else
{
innerType = NullableUnderlyingType ?? type;
innerType = ValueType;
}
if (innerType.IsEnum)
{
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void EnsureNoAuthenticationSchemeSpecified()

/// <summary>
/// <para lang="zh">获得唯一类型名称方法</para>
/// <para lang="en">Gets唯一type名称方法</para>
/// <para lang="en">Gets a unique type name</para>
/// </summary>
/// <param name="type"></param>
public static string GetUniqueTypeName(this Type type) => type.IsCollectible
Expand All @@ -68,7 +68,7 @@ public static string GetUniqueTypeName(this Type type) => type.IsCollectible

/// <summary>
/// <para lang="zh">通过 typeName 参数安全获取 Type 实例</para>
/// <para lang="en">通过 typeName 参数安全获取 Type instance</para>
/// <para lang="en">Gets a Type instance safely from the typeName parameter</para>
/// </summary>
/// <param name="typeName"></param>
public static Type? GetSafeType(string? typeName)
Expand Down
Loading