FxCop 规则不与空值进行比较
我正在尝试为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有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.