【发布时间】:2012-11-03 09:54:46
【问题描述】:
我正在尝试使用 nDepend 提供的 CQL 检索程序集中所有方法的所有直接间接方法调用。 问题是我无法遍历程序集中的所有方法来获取此信息。
DepthOfIsUsedBy 只允许字符串类型而不是字符串集合。
有没有办法为程序集中的所有方法获取此信息?
【问题讨论】:
我正在尝试使用 nDepend 提供的 CQL 检索程序集中所有方法的所有直接间接方法调用。 问题是我无法遍历程序集中的所有方法来获取此信息。
DepthOfIsUsedBy 只允许字符串类型而不是字符串集合。
有没有办法为程序集中的所有方法获取此信息?
【问题讨论】:
使用DepthOfIsUsing() 方法而不是DepthOfIsUsedBy() 怎么样:o)
from m in Assemblies.WithNameNotIn("nunit.uikit").ChildMethods()
let depth0 = m.DepthOfIsUsing("nunit.uikit")
where depth0 >= 0 orderby depth0
select new { m, depth0 }
这个查询是通过下面的菜单生成的。 (顺便说一句,可以使用魔术方法FillIterative() 来阐述更复杂的解决方案,但这里没有必要)。
考虑到 Prasad 的评论,试试这个列出所有来自 A 的直接和间接调用者的查询,对于 B 的每个方法:
from m in Assemblies.WithNameIn("AsmB").ChildMethods()
where m.IsPubliclyVisible // Optimization
let indirectcallers = m.MethodsCallingMe
.FillIterative(
callers => callers.SelectMany(m1 => m1.MethodsCallingMe))
.DefinitionDomain
.Where(m1 => m1.ParentAssembly.Name == "AsmA")
.ToArray() // Avoid double enumeration
where indirectcallers.Length > 0
orderby indirectcallers.Length descending
select new { m, indirectcallers }
【讨论】: