Skip to content

Commit 7c1a589

Browse files
committed
refactor: 代码重构提高可读性
1 parent fdd97e3 commit 7c1a589

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/BootstrapBlazor/Components/Select/Select.razor.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,7 @@ private SelectedItem? SelectedRow
175175
return null;
176176
}
177177

178-
if (IsVirtualize)
179-
{
180-
_init = false;
181-
return new SelectedItem(CurrentValueAsString, DefaultVirtualizeItemText ?? CurrentValueAsString);
182-
}
183-
184-
var item = GetItemWithEnumValue()
185-
?? Rows.Find(i => i.Value == CurrentValueAsString)
186-
?? Rows.Find(i => i.Active)
187-
?? Rows.FirstOrDefault(i => !i.IsDisabled);
188-
178+
var item = IsVirtualize ? GetItemByVirtulized() : GetItemByRows();
189179
if (item != null)
190180
{
191181
if (_init && DisableItemChangedWhenFirstRender)
@@ -201,9 +191,18 @@ private SelectedItem? SelectedRow
201191
return item;
202192
}
203193

204-
private SelectedItem? GetItemWithEnumValue() => ValueType.IsEnum
205-
? Rows.Find(i => i.Value == Convert.ToInt32(Value).ToString())
206-
: null;
194+
private SelectedItem? GetItemWithEnumValue() => ValueType.IsEnum ? Rows.Find(i => i.Value == Convert.ToInt32(Value).ToString()) : null;
195+
196+
private SelectedItem GetItemByVirtulized() => new(CurrentValueAsString, DefaultVirtualizeItemText ?? CurrentValueAsString);
197+
198+
private SelectedItem? GetItemByRows()
199+
{
200+
var item = GetItemWithEnumValue()
201+
?? Rows.Find(i => i.Value == CurrentValueAsString)
202+
?? Rows.Find(i => i.Active)
203+
?? Rows.FirstOrDefault(i => !i.IsDisabled);
204+
return item;
205+
}
207206

208207
/// <summary>
209208
/// <inheritdoc/>

0 commit comments

Comments
 (0)