导出 .NET 中的圈复杂度
我知道我可以通过右键单击并选择“计算代码指标”来访问 Visual Studio 2008 团队资源管理器中代码的圈复杂度。 我想公开此数据以供 Web 应用程序显示。 有谁知道通过 API 访问这些数据的方法吗?
感谢您的帮助!
I know that I can access the cyclomatic complexity to my code in Visual Studio 2008 Team Explorer by right clicking and selecting "Calculate Code Metrics". I would like to expose this data for a web application to display it. Does anybody know of any way of accessing this data through an API?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
柳若烟2024-07-23 08:23:21
如本答案中所述,可以利用Gendarme开源工具的API来计算方法的圈复杂度
ModuleDefinition module = ModuleDefinition.ReadModule(fullPathToTheAssembly);
foreach (var type in module.Types)
{
foreach (var me in type.Methods)
{
if (!me.HasBody || me.IsGeneratedCode() || me.IsCompilerControlled)
continue;
var r = AvoidComplexMethodsRule.GetCyclomaticComplexity(me);
Console.WriteLine("{0}: {1}", me.ToString(), r);
}
}
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我使用 NDepend 来处理类似的事情。 您可以在 NDepend 中创建 CQL 查询并执行它们。
示例:
返回圈复杂度大于 8 的方法。
I use NDepend for stuff like that. You can create CQL queries in NDepend and execute them.
Example:
returns the methods with a cyclomatic complexity greater than 8.