免费的C#量度计算库(DLL) [英] Free C# metrics calculation library (DLL)
问题描述
我想问问你是否知道这件事计算CK指标(主要是圈复杂度)一些免费的C#库(DLL)。
I wanted to ask whether you know about some free C# libraries (dlls) that calculate CK metrics (mainly Cyclomatic Complexity).
我需要,对于一个项目,我打算这样做。我知道已经有一些成品的解决方案,计算CK指标,并以各种形式展示给你,但我需要一个,我可以从我的应用程序中使用。于是开始和编写一个自己之前,我首先想问问你。
I would need that for a project I'm planning to do. I know that there are already some finished solutions that calculate CK metrics and display it to you in various forms, but what I would need is one that I could use from within my application. So before starting and writing one myself I first wanted to ask you.
感谢
推荐答案
DrivenMetrics 是一个开源的C#命令行工具。核心功能是通过命令行控制台客户端,分离出库(核心项目,请这里)。
DrivenMetrics is a open source C# command line tool. The core functionalities are isolated from the command line console client as a library (Core project is available here).
即使很简单,它可能适合你的需要:它是免费的,计算行数,并计算方法的圈复杂度(潜在code路径号)。
Even if quite simple, it may fit your need: it's free, counts the the number of lines and calculates the cyclomatic complexity (number of potential code paths) of methods.
这是通过IL感谢 Mono.Cecil能做到(同一库NDepend的依赖)的直接分析进行。这样就可以从写在C#code内置组件进行的分析,VB.Net,...
This is performed through direct analysis of the IL thanks to Mono.Cecil (the same library NDepend relies on). This allows the analysis to be performed on assemblies built from code written in C#, VB.Net,...
更新:
另一种选择将是的惊人的宪兵,从单项目静态分析工具。
Another option would be the amazing Gendarme, a static analysis tool from the Mono project.
由于使用的样本中,code下面显示的每个方法在装配圈复杂度。
As a sample of usage, the code below display the cyclomatic complexity of every method in an assembly.
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);
}
}