ReSharper 中可能存在 null 赋值。我不明白那怎么可能是空的?
我收到以下警告:
可能对标有“值不能”的实体进行“空”赋值 null' 属性
我的代码:
if (verifier.GetType().GetInterface(typeof(IAsyncVerifier).FullName, true) == null)
{
continue;
}
在 typeof(IAsyncVerifier).FullName
部分给出警告。那怎么可以为空呢?你会如何解决它?或者也许有更好的方法来确定对象是否实现特定接口?
I get following warning:
Possible 'null' assignment to an entity marked with 'Value cannot be
null' attribute
My code:
if (verifier.GetType().GetInterface(typeof(IAsyncVerifier).FullName, true) == null)
{
continue;
}
Warning given on typeof(IAsyncVerifier).FullName
part. How that can be null? How would you fix it? Or maybe there is better way to figure if object implements specific interface?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者也许有更好的方法来确定对象是否实现特定接口?
使用 is 运算符来检查对象的类型是否派生自特定接口或类
请参阅这篇 MSDN 文章 Type.FullName 它表示该属性不会返回任何内容。
如果您确定在访问 FullName 时这在任何情况下都不会为空,您可以使用
//resharper disable
注释禁用此警告Or maybe there is better way to figure if object implements specific interface?
Use is operator for to check if an object's type is derived from a particular interface or class
Look at this MSDN article Type.FullName It says that property will return nothing.
If you are sure that when you access FullName this will not be null in any case you can disable this warning using
//resharper disable
comment