Refactoring in C# using NDepend

mteheran

Miguel Teheran

Posted on October 12, 2020

Refactoring in C# using NDepend

One of the activities that I love to do in legacy projects is to make a refactoring in the code. We have to be careful because finally, we are updating code that is working fine in production. In the ideal scenario, we have Unit tests and Automation tests to avoid issues during refactoring.

We have many tools like CodeMaid, Resharper, and even Visual Studio have good tools to do this job or activity but in this article, I will talk about NDepend.

NDepend has a lot of tools to analyze a piece of code, a project, or a whole solution. It will show a report including warnings and issues found, there are many rules that NDepend has in order to validate our code.

Here an example:

Report NDepend

We can analyze the issues reported and update our code properly, finally, we can run the analysis once again and see the results. Even this is the general propose of NDepend I want to keep the focus on the Power tools because for me are the most useful functionalities that we can find in NDepend.

Go to Tools -> Start Power Tools and it will show a new terminal with some options that we can perform on our projects.

NDepend Power Tools

All tools are great and useful for refactoring, But I will want to mention my favorites.

Search for duplicate code

This tool helps to find duplicated code where we can make refactoring creating functions or removing some lines.

NDepende code duplicated

Find Potential Death Code

With this tool, you can find potential death code in your projects. For example, a type that is never used or function that is never called.

Alt Text

Detect Assemblies Versionning and Deployment Issues

With this tool, we can detect the difference in the assemblies' version into the project and target framework.
Alt Text

You can try NDepend for 14 days: https://www.ndepend.com/download

💖 💪 🙅 🚩
mteheran
Miguel Teheran

Posted on October 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Refactoring in C# using NDepend
csharp Refactoring in C# using NDepend

October 12, 2020