导出 .NET 中的圈复杂度

发布于 2024-07-16 08:23:21 字数 136 浏览 7 评论 0原文

我知道我可以通过右键单击并选择“计算代码指标”来访问 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 技术交流群。

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

发布评论

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

评论(4

公布 2024-07-23 08:23:21

我使用 NDepend 来处理类似的事情。 您可以在 NDepend 中创建 CQL 查询并执行它们。
示例:

SELECT METHODS  WHERE CC > 8

返回圈复杂度大于 8 的方法。

I use NDepend for stuff like that. You can create CQL queries in NDepend and execute them.
Example:

SELECT METHODS  WHERE CC > 8

returns the methods with a cyclomatic complexity greater than 8.

柳若烟 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);
    }
}

As described in this answer, one can leverage the API of the Gendarme open source tool to calculate the cyclomatic complexity of a method

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);
    }
}
独留℉清风醉 2024-07-23 08:23:21

没有API。 但您可以读取 代码指标电动工具。 因此,您可以通过命令行生成代码指标 XML 文件,如下所示:

metrics /f:MyAssembly.dll /o:MetricsResults.xml

然后从 MetricsResults.xml 中获取所需的数据。

有关此强大工具的详细信息 这里

如果要在 TFS 构建中运行代码指标,请参阅 此处此处 查看选项。

There is no API. But you can read an XML file generated by the Code Metrics Power Tool. So you would generate the code metrics XML file by command line like:

metrics /f:MyAssembly.dll /o:MetricsResults.xml

Then grab the data you want out of MetricsResults.xml.

More info on the power tool here.

If you want to run code metrics in your TFS build, see here and here for options.

记忆で 2024-07-23 08:23:21

我不知道——Visual Studio 有任何此类 API 吗? ——但是计算圈复杂度相当容易。 宪兵可能就是您的答案。

I don't -- does Visual Studio have any APIs of that sort? -- but computing cyclomatic complexity is reasonably easy. Gendarme might be your answer.

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