查找方法的所有用途使用NDepend的(包括通过接口) [英] Find all uses of a method (including via interface) using NDepend
问题描述
使用 NDepend的,我怎么能找到所有,直接和间接使用特定的方法或属性?
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] }
此查询的两大基石是:
- 来的 FillIterative()递归选择间接呼叫。
- 来属性的 IMethod.OverriddensBase ,顾名思义。对于方法的 M 此方法返回一个基类或接口声明的所有方法的枚举,通过的 M
- The call to FillIterative() to select recursively the indirect call.
- The call to the property IMethod.OverriddensBase, as its name suggests. For a method M this returns the enumerable of all method declared in a base class or an interface, overriden by M.
这篇关于查找方法的所有用途使用NDepend的(包括通过接口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!