Skip to content

Repository files navigation

DotNetCodeMetrics

This is a standalone tool for calculating code metrics.

The code is pulled directly from the dotnet/roslyn repository.

Official documentation for the original tool can be found here

Discussion on this topic can be found here

As such, this repository has the same license.

Additionally, we hope to keep the same functionality while also making it available as a public API.

Public API

Use DotNetCodeMetricsAnalyzer.GetMetricsAsync to get flattened metric results with stable symbol ids, names, source locations, and metric values.

using DotNetCodeMetrics.Core;

var methodMetrics = await DotNetCodeMetricsAnalyzer.GetMetricsAsync(
    ["src/MyProject/MyProject.csproj"],
    CodeMetricsOptions.ForMethods());

foreach (var metric in methodMetrics)
{
    Console.WriteLine($"{metric.FullyQualifiedName}: {metric.Location?.FilePath}:{metric.Location?.StartLine}");
}

To return class/type metrics only:

var classMetrics = await DotNetCodeMetricsAnalyzer.GetMetricsAsync(
    ["src/MyProject/MyProject.csproj"],
    CodeMetricsOptions.ForClasses("MyNamespace.MyClass"));

CodeMetricsOptions can filter by TargetKinds, Name, FullyQualifiedName, and FilePath.

About

Code Metrics for DotNet Code: Based on Roslyn Analyzer

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages