我可以告诉NDepend忽略单个结果吗? [英] Can I tell NDepend to ignore a single result?

查看:109
本文介绍了我可以告诉NDepend忽略单个结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS 2012中针对我的C#项目运行NDepend.我已经查看了一个特别的严重违反规则",并决定我想保持原样.我想告诉NDepend忽略这一违规行为,而不是将其计入我的关键规则违规计数中,以便使底部的点不再是红色.

I'm running NDepend against my C# project in VS 2012. There is a particular "critical rule violation" that I have looked at and have decided that I want to leave as-is. I want to tell NDepend to ignore this one violation and NOT count it against my critical rule violation count, so that I can get the dot at the bottom to be no longer red.

如果重要:这是参数过多的函数".该功能的目的是在数据库表中建立一个日志条目,我需要传入所有值(其中的11个)以填充表(在对它们应用一些逻辑之后).我想我可以将所有值放入一个结构或类中,并将其作为单个值传递,但是对结构/类而言,除了调用此函数外,别无他用,所以对我来说似乎有点愚蠢.

If it matters: It's a "function with too many parameters". The purpose of function is to make a log entry into a database table, and I need to pass in all of the values (11 of them) to populate the table (after applying some logic to them). I suppose I could put all the values into a struct or class and pass that in as a single value, but there would be no other use for the struct/class than to call this one function, so that seems kind of silly to me.

因此,我一直在寻找一种方法,例如右键单击结果并选择永久忽略此结果",就像您可能使用拼写检查器一样,但是我看不到任何此类选项.

So, I was looking for a way to just do something like right-clicking on the result and choosing "permanently ignore this result", like you might do with a spell checker, but I don't see any such option.

有没有办法做到这一点?

Is there a way to do this?

我不想排除整个规则或对其进行修改以增加参数的最大数量,因为在其他情况下,我确实同意应对该函数进行修改.

I don't want to exclude the entire rule or modify it to increase the max number of parameters, as there may be other instances where I DO agree that the function should be modified.

推荐答案

您可以通过以下方式修改CQLinq规则主体:

You can modify the CQLinq rule body this way:

// <Name>Methods with too many parameters</Name>
warnif count > 0 from m in JustMyCode.Methods
.WithFullNameNotIn("MyNamespace.MyType.MyMethod1(String,Int32,Int32,Boolean,String,Int32,Int32,Boolean,String,Int32,Int32,Boolean)", 
                   "MyNamespace.MyType.MyMethod2(String,Int32,Int32,Boolean,String,Int32,Int32,Boolean,String,Int32,Int32,Boolean)",
                   ...)
where 
  m.NbParameters > 5 
  orderby m.NbParameters descending
select new { m, m.NbParameters }

请注意,规则主体包含用于排除全名的方法.要获取方法的全名,只需在结果中右键单击该方法,然后选择菜单将名称复制到剪贴板.

Notice that the rule body contains the method(s) to exclude full names. To get the method full name, just right click the method in the result and choose the menu Copy name to clipboard.

或者,如果您希望从所有规则结果中禁止某个方法,则可以使用 JustMyCode/notmycode工具.

Alternatively, if you wish to suppress a method from all rules results, you can use the JustMyCode/notmycode facility.

这篇关于我可以告诉NDepend忽略单个结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆