“如果 X = Nothing”的 FXCop 规则 当 X 是可为空整数时

发布于 2024-07-09 17:38:21 字数 283 浏览 10 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦毁影碎の 2024-07-16 17:38:21

可以在这里找到编写自定义 FxCop 规则的另一个好资源:binarycoder

Another good resource for writing custom FxCop rules can be found here: binarycoder

鯉魚旗 2024-07-16 17:38:21

学习为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文