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):

<interactivity:Interaction.Behaviors>

<behaviors:TouchDrag TouchDragEnabled="True"/>

<behaviors:TouchZoom TouchZoomEnabled="True"/>

</interactivity:Interaction.Behaviors>

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:

DependencyGraph

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):

InteractivityMetrics

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

Metrics

Metrics about “Interaction”, 140 IL instructions:

InteractionsMetrics

Metrics about “TriggerBase”, 122 IL instructions:

InteractionsTriggerBase

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:

DependencyMatrix

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

ObjetcsInvolvedGraph

 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!

2 thoughts on “NDepend: a great tool to analyze Silverlight / Expression assemblies and save precious time”

Leave a Reply

Your email address will not be published. Required fields are marked *