提问人:Predrag Despotovic 提问时间:9/2/2022 最后编辑:Jon SkeetPredrag Despotovic 更新时间:9/2/2022 访问量:64
显示可能的空引用警告的取消引用的标准是什么?
What is the criteria for showing a dereference of a possible null reference warning?
问:
我的洋葱微服务架构中有一个 QueryExecutor 文件,我在下面的代码中收到了可能为空引用警告的取消引用:
public async Task<IReadOnlyCollection<T>> GetAll<T>() where T : BaseEntity
=> await _mongoDbContext.GetCollection<T>()
.Find(_ => true).ToListAsync();
public async Task UpdateAsync<T>(FilterDefinition<T> filterDefinition, UpdateDefinition<T> updateDefinition) where T : BaseEntity
=> await _mongoDbContext.GetCollection<T>()
.UpdateOneAsync(filterDefinition, updateDefinition);
只有 Update 方法发出警告,我想我理解它 - mongoDbContext.GetCollection() 可以返回一个 null 值。但我不明白的是为什么 GetAll 方法不返回它。我看到的唯一区别是 Update 返回值是一个 void Task,而 Update 有一个只读集合。
答: 暂无答案
评论