【发布时间】:2021-11-15 20:30:13
【问题描述】:
当我使用 Fluent 断言来测试一个属性是否不为空时,分析器仍然会抱怨后续行将该行取消引用为可能为空。在使用 FluentAssertions 进行测试后,有什么方法可以让编译器将属性识别为不为空? 例如
Foo? foo = Bar();
foo.Should().NotBeNull();
foo.Value.Should().Be(5); // Warning about dereference of a possibly null reference on this line
我知道我可以使用 !在第二行的 foo 上,但有什么方法可以让分析器自己解决这个问题?
我确实找到了this,但我看不出在这种情况下如何使用它。
【问题讨论】:
标签: c# .net-5 fluent-assertions nullable-reference-types