1

I can find indirect dependencies using CQLinq / NDepend, and using the magic "FillIterative"-Method I can filter the found dependencies. Accessing the "DefinitionDomain" afterwards can give me the depth of the dependency path (how many hops).

My question now is: Can I somehow add the dependency path to each entry in my query results? So for a query that lists all indirect usages of the Member "Target" together with the depth-of-usage, instead of results of the form

method          depth
------------------------------------------------------------------------
Foo             2
Bar             1
Baz             0

I'd get results of the form

method          depth          path
------------------------------------------------------------------------
Foo             2              Foo, Something1, Something2, Target
Bar             1              Bar, Something3, Target
Baz             0              Baz, Target

...is this possible?

Edit: Here's my query so far:

// <Name>Async methods must not use non-async variants of EnsureInThisCtx methods, even indirectly</Name>
warnif count > 0
let mse = Methods.WithFullNameLike("DbContext\\.EnsureIsInThisCtx[^A]")
let m1 = mse.First()       // there are two overloads
let m2 = mse.ElementAt(1)  // of the method I want to catch.
let icd1 = m1.ToEnumerable().FillIterative(methods => methods.SelectMany(m => m.MethodsCallingMe.Union(m.OverriddensBase)))
let icd2 = m2.ToEnumerable().FillIterative(methods => methods.SelectMany(m => m.MethodsCallingMe.Union(m.OverriddensBase)))
let hits1 = (from m in icd1.DefinitionDomain where m.IsAsync select m)
let hits2 = (from m in icd2.DefinitionDomain where m.IsAsync select m)
from m in hits1.Union(hits2).Distinct()
let dist1=icd1[m]
let dist2=icd2[m]
select new { m, DepthOfUsageVariant1=dist1, DepthOfUsageVariant2=dist2 }

And example output looks like this:

methods         DepthOfUsageVariant1  DepthOfUsageVariant2
------------------------------------------------------------------------
Foo             2                     0
Bar             0                     1
...
  • could you please add the query you came up with + does this help? http://www.ndepend.com/docs/visual-studio-dependency-graph#AllPaths – Patrick from NDepend team Dec 08 '16 at 15:26
  • Hey, I added my attempt. The link you posted my point into another direction (looking at DepthOfIsUsing *and* DepthOfIsUsedBy together), but I don't know how to incorporate this. – Dr. Tim dos Santos Dec 09 '16 at 08:24

0 Answers0