FxCop 规则不与空值进行比较

发布于 2024-07-17 11:45:03 字数 781 浏览 4 评论 0原文

我正在尝试为 fxcop 编写一条规则来执行此操作:

如果某个类与 null 进行比较,则出现错误。

你认为这可能吗?

我按照语句降序编写了一部分代码,我可以找到我正在寻找的类型,但不知道如何找到该值。

因为我知道我已经得到了该代码,但不知道该去哪里..

public override ProblemCollection Check(Microsoft.Cci.Member member)
        {
            Method m = member as Method;

            if (m != null)
            {   
                foreach (Statement s in m.Body.Statements)
                {
                    Block b = s as Block;
                    if (b != null)
                    {
                        foreach (Statement s1 in b.Statements)
                        {
                          ?
                        }
                    }
                }
            }

            return this.Problems;
        }

I'm trying to write a rule for fxcop doing this:

if a certain class is compared to null then error.

Do you think it's possible ?

I wrote a part of code descending ti the statements i could find the type i was looking for but didn't know how to find the value.

for know i've got that code but dont know where to go then..

public override ProblemCollection Check(Microsoft.Cci.Member member)
        {
            Method m = member as Method;

            if (m != null)
            {   
                foreach (Statement s in m.Body.Statements)
                {
                    Block b = s as Block;
                    if (b != null)
                    {
                        foreach (Statement s1 in b.Statements)
                        {
                          ?
                        }
                    }
                }
            }

            return this.Problems;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

泅人 2024-07-24 11:45:03

如果您有reflector,您可以从Microsoft.FxCop.Rules.Performance.TestForEmptyStringsUsingStringLength 的代码 - 它执行与您要编写的规则类似的操作。

If you've got reflector, you could take inspiration from the code for Microsoft.FxCop.Rules.Performance.TestForEmptyStringsUsingStringLength - it does something similar to the rule you're looking to write.

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