我对收到的警告有些困惑。以下是相关代码:
#nullable enable
public partial class FileTable<TItem> : ComponentBase, IDisposable
{
// bunch of class code
public async Task FilterColumn(Func<TItem, IComparable>? itemProperty, string? searchString)
{
ArgumentNullException.ThrowIfNull(ViewItems);
if (itemProperty == null)
return;
if (searchString == null)
searchString = string.Empty;
await Task.Run(() =>
{
foreach (var item in ViewItems)
{
var property = itemProperty(item.Item);
if (property == null)
continue;
item.IsVisible = property.ToString().ToLower().Contains(searchString.ToLower());
}
});
StateHasChanged();
}
}
我在property.ToString()
处收到警告。如您所见,我已添加了许多null检查,但似乎没有一个能消除该警告。就我所知,此时property
不可能是null
。显然,我错过了什么...那么是什么触发了这个警告?
property
的数据类型是什么,而itemProperty()
的返回类型是什么? - gunr2171itemProperty()
来搜索相应列的属性。 - Roland Deschain