“如果 X = Nothing”的 FXCop 规则 当 X 是可为空整数时
1 Dim x as Integer? = Nothing
2 If x = Nothing Then
3 'this is what I think will happen
4 Else
5 'this is what really happens
6 End If
正确的写法是“If x Is Nothing”。
是否有 FXCop 规则来检查这一点? 或者更好的是,有人可以告诉我如何写自己的吗?
乔纳森
1 Dim x as Integer? = Nothing
2 If x = Nothing Then
3 'this is what I think will happen
4 Else
5 'this is what really happens
6 End If
The proper way to write that is "If x Is Nothing".
Is there a FXCop rule that checks for this? Or better yet, can someone show me how to write my own?
Jonathan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在这里找到编写自定义 FxCop 规则的另一个好资源:binarycoder
Another good resource for writing custom FxCop rules can be found here: binarycoder
学习为 FXCop 编写自定义规则的最佳选择是论坛 此处 它涉及编写自定义程序集来解析代码并检查它。
具体来说,您想要编写一条规则,表示“不要对可空类型使用 = Nothing,而是确保使用 hasvalue。
Your best bet to learn to write custom rules for FXCop is the forum here It involves writing an custom assembly to parse the code and check it.
Specifically you want to write a rule that says "Instead of using = nothing for a nullable type make sure you use hasvalue.