How do you display the relationships that connect ClassA to ClassX using NDepend?

100 Views Asked by At

BACKGROUND

When driving through an unknown city, it is often preferable to have a map that can help guide you to your destination. Similarly, when looking at legacy code for the first time it is often preferable to have a diagram that can outline relationships within the application.

EXAMPLE

In this case, I have been asked to look at a legacy {data-centric} application to better understand how it manages it's database connections. Or more specifically, I am trying to generate a class diagram that outlines the relationships between Program and System.Data.Common.DbConnection.

THE PROBLEM

I am relatively new to NDepend, and am having difficulty writing the appropriate CQLinq statement. Unfortunately, the following only displays assemblies and their relationships to each other. How would I modify this query to display the relationships between two types?

Any insight you can provide would be greatly appreciated!

from t in Assemblies
where t.DepthOfIsUsedBy("MyCompany.MyProject.MyNamespace.Program") >=0 &&
t.DepthOfIsUsing("System.Data.Common.DbConnection") >=0
select new { t, t.NbLinesOfCode}
1

There are 1 best solutions below

0
On BEST ANSWER

from t in Assemblies means that t is an assembly.

You should try from t in Application.Types:

// <Name>Display relationships between two types</Name>
from t in Application.Types
where t.DepthOfIsUsedBy("Company.Project.NamespaceA") >=0 &&
t.DepthOfIsUsing("Company.Project.NamespaceZ") >=0
select new { t, t.NbLinesOfCode}