mirror of
https://github.com/dotnetcore/BootstrapBlazor.git
synced 2025-12-20 10:26:41 +08:00
refactor(Display): make TValue as nullable (#4651)
This commit is contained in:
@@ -188,7 +188,7 @@ public partial class CheckboxList<TValue> : ValidateBase<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
protected override string? FormatValueAsString(TValue value)
|
||||
protected override string? FormatValueAsString(TValue? value)
|
||||
{
|
||||
string? ret = null;
|
||||
if (ValueType == typeof(string))
|
||||
|
||||
@@ -355,7 +355,7 @@ public partial class DateTimePicker<TValue>
|
||||
/// <summary>
|
||||
/// 格式化数值方法
|
||||
/// </summary>
|
||||
protected override string FormatValueAsString(TValue value)
|
||||
protected override string FormatValueAsString(TValue? value)
|
||||
{
|
||||
var ret = "";
|
||||
DateTime? d = value switch
|
||||
|
||||
@@ -48,13 +48,13 @@ public abstract class DisplayBase<TValue> : BootstrapModuleComponentBase
|
||||
/// Gets or sets a callback that updates the bound value.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<TValue> ValueChanged { get; set; }
|
||||
public EventCallback<TValue?> ValueChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an expression that identifies the bound value.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Expression<Func<TValue>>? ValueExpression { get; set; }
|
||||
public Expression<Func<TValue?>>? ValueExpression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示前置标签 默认值为 null 为空时默认不显示标签
|
||||
@@ -164,7 +164,7 @@ public abstract class DisplayBase<TValue> : BootstrapModuleComponentBase
|
||||
/// </summary>
|
||||
/// <param name="value">The value to format.</param>
|
||||
/// <returns>A string representation of the value.</returns>
|
||||
protected virtual string? FormatValueAsString(TValue value)
|
||||
protected virtual string? FormatValueAsString(TValue? value)
|
||||
{
|
||||
string? ret;
|
||||
if (value is SelectedItem item)
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
|
||||
/// 获得/设置 格式化字符串
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<TValue, string>? Formatter { get; set; }
|
||||
public Func<TValue?, string>? Formatter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 格式化字符串 如时间类型设置 yyyy-MM-dd
|
||||
@@ -182,7 +182,7 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
protected override string? FormatValueAsString(TValue value) => Formatter != null
|
||||
protected override string? FormatValueAsString(TValue? value) => Formatter != null
|
||||
? Formatter.Invoke(value)
|
||||
: (!string.IsNullOrEmpty(FormatString) && value != null
|
||||
? Utility.Format(value, FormatString)
|
||||
|
||||
@@ -39,13 +39,13 @@ public partial class BootstrapInputNumber<TValue>
|
||||
/// 获得/设置 数值增加时回调委托
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<TValue, Task>? OnIncrement { get; set; }
|
||||
public Func<TValue?, Task>? OnIncrement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 数值减少时回调委托
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<TValue, Task>? OnDecrement { get; set; }
|
||||
public Func<TValue?, Task>? OnDecrement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 最小值
|
||||
@@ -161,9 +161,9 @@ public partial class BootstrapInputNumber<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value">The value to format.</param>
|
||||
/// <returns>A string representation of the value.</returns>
|
||||
protected override string? FormatValueAsString(TValue value) => UseInputEvent ? _lastInputValueString : GetFormatString(value);
|
||||
protected override string? FormatValueAsString(TValue? value) => UseInputEvent ? _lastInputValueString : GetFormatString(value);
|
||||
|
||||
private string? GetFormatString(TValue value) => Formatter != null
|
||||
private string? GetFormatString(TValue? value) => Formatter != null
|
||||
? Formatter.Invoke(value)
|
||||
: (!string.IsNullOrEmpty(FormatString) && value != null
|
||||
? Utility.Format(value, FormatString)
|
||||
@@ -175,7 +175,7 @@ public partial class BootstrapInputNumber<TValue>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
protected virtual string? InternalFormat(TValue value) => value switch
|
||||
protected virtual string? InternalFormat(TValue? value) => value switch
|
||||
{
|
||||
null => null,
|
||||
int @int => BindConverter.FormatValue(@int, CultureInfo.InvariantCulture),
|
||||
@@ -288,7 +288,7 @@ public partial class BootstrapInputNumber<TValue>
|
||||
}
|
||||
}
|
||||
|
||||
private TValue SetMin(TValue val)
|
||||
private TValue? SetMin(TValue? val)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Min))
|
||||
{
|
||||
@@ -317,7 +317,7 @@ public partial class BootstrapInputNumber<TValue>
|
||||
return val;
|
||||
}
|
||||
|
||||
private TValue SetMax(TValue val)
|
||||
private TValue? SetMax(TValue? val)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Max))
|
||||
{
|
||||
|
||||
@@ -81,7 +81,7 @@ public partial class RadioList<TValue> : CheckboxList<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
protected override string? FormatValueAsString(TValue value) => value is SelectedItem v ? v.Value : value?.ToString();
|
||||
protected override string? FormatValueAsString(TValue? value) => value is SelectedItem v ? v.Value : value?.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -211,7 +211,7 @@ public partial class MultiSelect<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
protected override string? FormatValueAsString(TValue value) => value == null
|
||||
protected override string? FormatValueAsString(TValue? value) => value == null
|
||||
? null
|
||||
: Utility.ConvertValueToString(value);
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ public partial class Transfer<TValue>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
protected override string? FormatValueAsString(TValue value) => value == null
|
||||
protected override string? FormatValueAsString(TValue? value) => value == null
|
||||
? null
|
||||
: Utility.ConvertValueToString(value);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class ValidateBase<TValue> : DisplayBase<TValue>, IValidateCompo
|
||||
/// <summary>
|
||||
/// Gets or sets the current value of the input.
|
||||
/// </summary>
|
||||
protected TValue CurrentValue
|
||||
protected TValue? CurrentValue
|
||||
{
|
||||
get => Value;
|
||||
set
|
||||
@@ -150,7 +150,7 @@ public abstract class ValidateBase<TValue> : DisplayBase<TValue>, IValidateCompo
|
||||
/// 获得/设置 Value 改变时回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<TValue, Task>? OnValueChanged { get; set; }
|
||||
public Func<TValue?, Task>? OnValueChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 类型转化失败格式化字符串 默认为 null
|
||||
|
||||
Reference in New Issue
Block a user