Skip to content

Commit 9c75eaa

Browse files
committed
refactor: 调整可为空
1 parent c4213a2 commit 9c75eaa

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace BootstrapBlazor.Components
22
@typeparam TValue
3-
@inherits ValidateBase<List<TValue?>>
3+
@inherits ValidateBase<List<TValue>>
44

55
@if (IsShowLabel)
66
{

src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public partial class CheckboxListGeneric<TValue> : IModelEqualityComparer<TValue
9797
/// 获得/设置 SelectedItemChanged 方法
9898
/// </summary>
9999
[Parameter]
100-
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue?>, Task>? OnSelectedChanged { get; set; }
100+
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue>, Task>? OnSelectedChanged { get; set; }
101101

102102
/// <summary>
103103
/// 获得/设置 最多选中数量
@@ -204,7 +204,7 @@ private async Task<bool> OnBeforeStateChanged(CheckboxState state)
204204
private async Task OnStateChanged(SelectedItem<TValue> item, bool v)
205205
{
206206
item.Active = v;
207-
var items = new List<TValue?>();
207+
var items = new List<TValue>();
208208
if (Value != null)
209209
{
210210
items.AddRange(Value);
@@ -217,7 +217,7 @@ private async Task OnStateChanged(SelectedItem<TValue> item, bool v)
217217
}
218218
else
219219
{
220-
items.Remove(val);
220+
items.Remove(val!);
221221
}
222222

223223
CurrentValue = items;

src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected override void OnParametersSet()
120120
var t = NullableUnderlyingType ?? typeof(TValue);
121121
if (t.IsEnum && Items == null)
122122
{
123-
Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default, NullItemText) : null);
123+
Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default!, NullItemText) : null);
124124
}
125125

126126
Items ??= [];

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ private async Task OnChange(ChangeEventArgs args)
566566

567567
if (item == null)
568568
{
569-
TValue? val = default;
569+
TValue val = default!;
570570
if (TextConvertToValueCallback != null)
571571
{
572572
val = await TextConvertToValueCallback(v);

src/BootstrapBlazor/Components/SelectGeneric/SelectOptionGeneric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected override void OnInitialized()
5858
Container?.Add(ToSelectedItem());
5959
}
6060

61-
private SelectedItem<TValue> ToSelectedItem() => new(Value, Text ?? "")
61+
private SelectedItem<TValue> ToSelectedItem() => new(Value!, Text ?? "")
6262
{
6363
Active = Active,
6464
GroupName = GroupName ?? "",

src/BootstrapBlazor/Misc/SelectedItemOfT.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class SelectedItem<T>
1313
/// <summary>
1414
/// 构造函数
1515
/// </summary>
16-
public SelectedItem() { }
16+
public SelectedItem() { Value = default!; }
1717

1818
/// <summary>
1919
/// 构造函数
2020
/// </summary>
2121
/// <param name="value"></param>
2222
/// <param name="text"></param>
23-
public SelectedItem(T? value, string text)
23+
public SelectedItem(T value, string text)
2424
{
2525
Value = value;
2626
Text = text;
@@ -34,7 +34,7 @@ public SelectedItem(T? value, string text)
3434
/// <summary>
3535
/// 获得/设置 选项值
3636
/// </summary>
37-
public T? Value { get; set; }
37+
public T Value { get; set; }
3838

3939
/// <summary>
4040
/// 获得/设置 是否选中

test/UnitTest/Components/CheckboxListGenericTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public void IsVertical_Ok()
7878
[Fact]
7979
public async Task NullItem_Ok()
8080
{
81-
var items = new List<SelectedItem<Foo>>()
81+
var items = new List<SelectedItem<Foo?>>()
8282
{
8383
new(null, "Select ..."),
8484
new(new Foo() { Id = 2, Name = "Test2" }, "Test 2")
8585
};
86-
var cut = Context.RenderComponent<CheckboxListGeneric<Foo>>(pb =>
86+
var cut = Context.RenderComponent<CheckboxListGeneric<Foo?>>(pb =>
8787
{
8888
pb.Add(a => a.Items, items);
8989
});

0 commit comments

Comments
 (0)