0

I'm trying to get the length of all the identifiers and methods of a project made in ASP.NET Core 2.2, in order to analize the code metrics for a homework, but I haven't found any kind of tool that provides that metric.

By far I've used Code Metrics of Visual Studio 2019, and I got the next metrics:

  • Maintainability Index
  • Cyclomatic Complexity
  • Depth of Inheritance
  • Class Coupling
  • Lines of Code

I wanna know if there's any tool that provides me the metric that I'm looking for.

2 Answers2

1

You can use the tool NDepend to compute the identifierLength metric. NDepend also supports many more code metrics.

For example you can write this C# LINQ code query. You can try yourself with the full featured trial available for download.

from m in Application.Methods
select new { m, identifierLength = m.SimpleName.Length }

code metric identifier Length with NDepend

Disclaimer: I work for NDepend

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
0

Using the reflection API, you can get all Types in the assembly with Assembly.GetTypes().

For each type you can get all methods with Type.GetMethods().

For each method you can get the MethodBody with MethodInfo.GetMethodBody().

You can then call GetILAsByteArray() on each MethodBody to get the IL as a byte array.

This is raw bytecode, but you could use the length of that byte array as a metric.

If you want to analyse the code as C#, you will need to disassemble it from IL with something like Reflector.

Igby Largeman
  • 16,495
  • 3
  • 60
  • 86