Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Free C# metrics calculation library (DLL) [closed]

I wanted to ask whether you know about some free C# libraries (dlls) that calculate CK metrics (mainly Cyclomatic Complexity).

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.

Thanks

like image 954
Juri Avatar asked Jun 27 '09 07:06

Juri


People also ask

What does free () do C?

The free() function in C library allows you to release or deallocate the memory blocks which are previously allocated by calloc(), malloc() or realloc() functions. It frees up the memory blocks and returns the memory to heap. It helps freeing the memory in your program which will be available for later use.

What is a free function?

The term free function in C++ simply refers to non-member functions. Every function that is not a member function is a free function.

What can you call free on in C?

When you call free(a) it means that the memory has been flagged for re-use. So, writing an array to a will still work, but it is undefined behavior. Chances are it will be overwritten later without you being notified about it. Secondly do not cast the return value of malloc() in C.

What does malloc () calloc () realloc () free () do?

allocates multiple block of requested memory. realloc() reallocates the memory occupied by malloc() or calloc() functions. free() frees the dynamically allocated memory.


3 Answers

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
like image 98
nulltoken Avatar answered Oct 16 '22 12:10

nulltoken


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.

like image 3
Mark Heath Avatar answered Oct 16 '22 13:10

Mark Heath


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

like image 1
Ashley Davis Avatar answered Oct 16 '22 12:10

Ashley Davis