Find all kinds of method use (including through the interface) using NDepend

Using NDepend , how can I find all, direct and indirect use of a particular method or property?

In particular, I need to find ways to use through the interface somewhere along the way of use. Thanks!

+6
source share
1 answer

Right-click the method anywhere in the user interface and select the menu: Select the method ...> ... that uses me (directly or indirectly) leads to a code request, for example:

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 a request gives indirect use, but does not look for calls that occur through the interface (or an overridden method declared in the base class).

We hope you receive a request for this request:

 // 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 edge stones of this request are:

  • Call FillIterative () to select a recursively indirect call.
  • Call the IMethod.OverriddensBase property, as its name suggests. For method M, this returns an enumerable entire method declared in the base class or interface, overridden by M.
+6
source

Source: https://habr.com/ru/post/917952/


All Articles