在.NET中派生圈复杂度 [英] Deriving Cyclomatic Complexity in .NET

查看:123
本文介绍了在.NET中派生圈复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过右键单击访问圈复杂到我的code在Visual Studio 2008团队资源管理器,然后选择计算code指标。我想公开此数据为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?

感谢您的帮助!

推荐答案

正如本 <一个描述href="http://stackoverflow.com/questions/1052269/free-c-metrics-calculation-library-dll/4005106#4005106">answer,人们可以利用宪兵开源工具的API来计算方法的圈复杂度

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);
    }
}

这篇关于在.NET中派生圈复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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