NDepend: a great tool to analyze Silverlight / Expression assemblies and save precious time

I usually work with early-stage products containing poor or no documentation, in such cases a tool to help understand the tools and libraries you are using can really be a time saver.

Recently I’ve received a gift by Patrick Smacchia, Microsoft C# MVP, author of a cool tool named NDepend which permits to analyze and  compare .NET libraries in order to better understand and eventually optimize your code.

In this period, a cool topic is examined in several community posts: Behaviors and their usage in Silverlight and Expression Blend. They are powerful and permit to easily reuse your code, wrap powerful animation and effects in your libraries and then visually insert them in your application using Blend (in this way the designer/developer work-flow integration is really simplified).

If you use a behavior in your application, you have to write something similar this, where interactivity represents the System.Windows.Interactivity namespace (see my previous post for the source code of these behaviors):


<behaviors:TouchDrag TouchDragEnabled="True"/>

<behaviors:TouchZoom TouchZoomEnabled="True"/>


Using NDepend it’s possible to analyze this namespace and obtain a Dependency graph to better understand the internal structure of Microsoft.Expression.Interactions and System.Windows.Interactivity:


But this is only a starting point, we can also analyze the Metrics and go in more detail into the Interactivity ns (curiosity: it contains 2348 IL instructions):


Metrics about “Behavior<T>”, 9 IL instructions:


Metrics about “Interaction”, 140 IL instructions:


Metrics about “TriggerBase”, 122 IL instructions:


The Dependency Matrix view permits to verify that  16 members of the namespace System.Windows.Interactivity are used by 36 methods of the assembly Microsoft.Expression.Interactions:


And then left-click the dependency matrix to see a graph of the objects involved:


 As you can see it’s very simple to quickly analyze (and learn) the structure of a selected library using NDepend, the graphical visualization of the relations between the objects is very useful to better understand the internals, and then become a better developer 🙂

More features available permit to compare different versions of the same libraries and perform custom queries to obtain more detailed information about the code using a dedicated language and syntax (this is a topic I’ve to investigate further, so stay tuned).

It’s my intention to start using NDepend regularly, its features are really incredible and are indispensable to understand the way of work of thirdy-part libraries.

Thank you Patrick for this great tool!