Calculating code metrics in Visual Studio
Every codebase I’ve ever worked with has had a few maintainability hot spots. These are areas that are frequently changed, have a higher degree of complexity than other areas of code, and represent serious quality risks to the software project.
These areas are usually some of the most critical to refactor and they tend to be easily discoverable using code metrics.
Code metrics calculate a handful of useful statistics about every file, class, method, and property in your C# code. This lets you spot hot spots in your code that have significantly higher complexity or lower maintainability. Code metrics can even help you find classes that are too large and likely violate the Single Responsibility Principle (SRP) as we discussed in Chapter 8.
To calculate code metrics, open your solution in Visual Studio and then click the Analyze menu, followed by Calculate Code Metrics, and then For Solution, as shown in Figure 12.1: