免费的 C# 指标计算库 (DLL)

发布于 2024-07-25 10:03:33 字数 1542 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

方圜几里 2024-08-01 10:03:33

DrivenMetrics 是一个开源 C# 命令行工具。 核心功能作为库与命令行控制台客户端隔离(核心项目可用 这里)。

即使非常简单,它也可能满足您的需求:它是免费的,计算行数并计算方法的圈复杂度(潜在代码路径的数量)。

这是通过直接分析 IL 来执行的,这要归功于 Mono.Cecil (NDepend 依赖于相同的库) )。 这允许对用 C#、VB.Net 编写的代码构建的程序集执行分析...


更新:

另一个选择是惊人的Gendarme,它是来自Mono项目的静态分析工具。

作为用法示例,下面的代码显示了程序集中每个方法的圈复杂度。

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);
    }
}
  • 该项目在此处进行了描述。
  • 代码源位于github
  • 打包版本也是 可用
  • 它适用于 Windows 和 Mono

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).

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.

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,...

  • The project has been announced
    here.
  • The code source is
    available on github.
  • A packaged release is also available.
  • It works both on Windows and Mono.

UPDATE:

Another option would be the amazing Gendarme, a static analysis tool from the Mono project.

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);
    }
}
  • The project is described here
  • The code source is available on github
  • Packaged releases are also available
  • It works both on Windows and Mono
随波逐流 2024-08-01 10:03:33

我正在使用 SourceMonitor,这是一个很好的免费软件应用程序,可以测量代码复杂性和其他指标多种语言,包括 C#。 我们从命令行驱动它以生成 XML 输出,然后使用 LINQ to XML 提取和排序我们感兴趣的数据。然后使用 NVelocity 创建 HTML 报告。

我知道它不是一个托管库,但您可能会发现它可以满足您的需要。

I am using SourceMonitor, which is a nice freeware app that measures code complexity and other metrics for a variety of languages including C#. We drive it from the command line to produce XML output, then we use LINQ to XML to extract and sort the data we are interested in. We then use NVelocity to create HTML reports.

I know its not a managed library, but you might find it can do what you need.

埋葬我深情 2024-08-01 10:03:33

我正在使用 Microsoft 的一个工具来计算 C# 程序集的代码指标。

包括环路综合体、可维护性指标等。

详细信息请参见:

http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx

在此处下载:

http://www.microsoft.com/en-us/download/details.aspx?id=9422

There is a tool from Microsoft I am using to compute code metrics for C# assemblies.

It includes cyclo complex, maintainability index and more.

Details here:

http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx

Download here:

http://www.microsoft.com/en-us/download/details.aspx?id=9422

她如夕阳 2024-08-01 10:03:33

它不是免费的,但我在 NCover 处理此类事情方面获得了很好的经验。 它们还与许多 CI 工具集成得很好。

It isn't free but I've had good experiences with NCover for this sort of thing. They also integrate pretty well with a lot of CI tools out there.

网白 2024-08-01 10:03:33

NDepend 支持 82 个代码指标,是 Roll 为 .NET 开发人员提供的代码指标工具(但是它是一个商业工具)。

With 82 code metrics supported NDepend is the code metrics Roll's Royce tooling for .NET developers (however it is a commercial tool).

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