Last week I was so lucky to get my hands on one of the most awesome software tools I’ve ever worked with. Even though I have worked with some static analysis tool, there were so many times I imagined if I could get some assembly or project analyzed and get it in to a visual diagram, where I could see the dependencies of each class, assembly and namespace. Thanks to Patrick Smacchia a C# MVP, finally my dream came true with the tool NDepend.
“Static analysis, also called static code analysis, is a method of computer program debugging that is done by examining the code without executing the program. The process provides an understanding of the code structure, and can help to ensure that the code adheres to industry standards. The principal advantage of static analysis is the fact that it can reveal errors that do not manifest themselves until a disaster occurs weeks, months or years after release.”
NDepend is a static analyzer. This is how the tool is introduced in the official site www.ndepend.com. NDepend is a tool that simplifies managing a complex .NET code base. Architects and developers can analyze code structure, specify design rules, plan massive refactoring, do effective code reviews and master evolution by comparing different versions of the code. The result is better communication, improved quality, easier maintenance and faster development.
Do I need say more… Let’s get in to action…
How easy it is to understand the underlying architecture of a particular assembly or a project specially which is compiled or deployed. Actually past few days I was bit busy working and writing about SharePoint Object Model. So I’ll take the assembly Microsoft.SharePoint.dll for the analysis process.
Opening the VisualNDepend.exe will open the Start Page of NDepend where you get easy access to recent projects (with new projects), Getting Started Guide and Visual Studio and Reflector Add-Ins as shown below.
Click File > Select .Net assemblies to Analyze will open a window where you can browse any assembly you need or it’s just a matter of very common drag and drop method from windows explorer.
As I mentioned earlier I’ll browse and select the assembly Microsoft.SharePoint.dll for the analysis process. Magic begins… Give few seconds/minutes and given below is what you will see. Just to my idea this product is super fast as for the information it analyzes. Specially the multi threading :)
Basically I'm trying to get the transitive closure of WorkflowRuntime. Transitive closure is a powerful mean to deconstruct software because it shows how the code is really layered.
Okay.. the result shown below.
I could have chosen the transitive closure made of methods, types or assemblies too. You can see a Query suggested by NDepend (more like a T-SQL Query) which is a Code Query Language (CQL) Query.
Let's see these namespaces mapped to a graph.
Below given is the result... which is the 1st reason that made me fall in love with this awesome product.
Let's say I wanna see the assemblies which are using the System.Workflow.Runtime on a graph. It has never been easier than this. Select the assembly name, right click and select "Who is using me on graph" as in the below screen.
This is only a single feature of NDepend which is the Dependency Graph. Next.. tune-in for the Dependency Matrix. If you want to see the features on one go, here it is.