.net - How to analyze how many different code paths are in a method

Is there a (preferred free) tool that can analyze how many different combinations are possible in a method? I am currently refactoring a method that has many many if / switch statments, and I'm curious how many possible different ways this method can execute.

Let's say I have a simple method:

public void DoSomething(bool flag1, int value) { if (flag1) { if (value > 0) { Console.WriteLine("Flag1 & value > 0"); return; } else { Console.WriteLine("Flag1 & value <= 0"); return; } } elseif (value > 0 and value < 10) { Console.WriteLine("Flag1 is false and value between 0 & 10"); return; } if (value < 0) { Console.WriteLine("Flag1 = false & value <= 0"); return; } elseif(value = 0) { Console.WriteLine("Flag1 = false & value >= 10"); return; } Console.WriteLine("nothing else matched"); } 

There should be 6 possible ways to execute this method. I know that there are tools that can calculate this number for me (I believe that Visual Studio Ultimate can do this, but, unfortunately, I only have a Professional version).

Maybe someone knows a good tool that can do this.

+6
c # code-coverage code-analysis
source share
6 answers

CodeMetrics is a free add-on for a fast reflector that does not have a longer time. I don't know how good this is, I got the correct version of VS.

0
source share

What do you mean by Cyclomatic Complexity , and this calculation is already included in VS 2010, check here on MSDN.

+3
source share

I am using a tool that can be integrated into VS2008 and VS2010. It can be found from http://www.blunck.info/ccm.html .

+2
source share

The metric you are looking for is cyclic complexity. There are some free tools, but I used only the built-in indicators of VS 2008 pro, so I can not judge them, but this should facilitate their search.

eg. http://www.codeproject.com/KB/architecture/Cyclomatic_Complexity.aspx

+1
source share

Code Metrics for Visual Studio

You need cyclomatic complexity.

+1
source share

You can also use the NDepend tool (integrated in Visual Studio 2010, 2008, 2005), which can calculate Cyclomatic Complexity on. NET Code:

  • from the source code definition here
  • from the IL code definition here

Cyclomatic Complexity to IL code is useful if you decompile the assembly without the appropriate source code.

+1
source share

All Articles