Using NDepend, how can I find all, direct and indirect, uses of a specific method or property?
In particular, I need to find usages that occur via an interface somewhere along the use path. Thanks!
Using NDepend, how can I find all, direct and indirect, uses of a specific method or property?
In particular, I need to find usages that occur via an interface somewhere along the use path. Thanks!
Right clicking a method anywhere in the UI, and selecting the menu: Select Method... > ...that are using me (directly or indirectly) leads to a code query like:
from m in Methods
let depth0 = m.DepthOfIsUsing("NUnit.Core.NUnitFramework+Assert.GetAssertCount()")
where depth0 >= 0 orderby depth0
select new { m, depth0 }
The problem is that such query gives indirect usage, but doesn't look for calls that occurs via an interface (or an overridden method declared in a base class).
Hopefully what you are asking for can be obtained with this query:
// Retrieve the target method by name
let methodTarget = Methods.WithFullName("NUnit.Core.NUnitFramework+Assert.GetAssertCount()").Single()
// Build a ICodeMetric<IMethod,ushort> representing the depth of indirect
// call of the target method.
let indirectCallDepth =
methodTarget.ToEnumerable()
.FillIterative(
methods => methods.SelectMany(
m => m.MethodsCallingMe.Union(m.OverriddensBase)))
from m in indirectCallDepth.DefinitionDomain
select new { m, callDepth = indirectCallDepth[m] }
The two corner stones of this query are:
© 2022 - 2024 — McMap. All rights reserved.