【问题标题】:nDepend querying direct indirect methods for all methods in an assemblynDepend 查询程序集中所有方​​法的直接间接方法
【发布时间】:2012-11-03 09:54:46
【问题描述】:

我正在尝试使用 nDepend 提供的 CQL 检索程序集中所有方​​法的所有直接间接方法调用。 问题是我无法遍历程序集中的所有方法来获取此信息。

DepthOfIsUsedBy 只允许字符串类型而不是字符串集合。

有没有办法为程序集中的所有方法获取此信息?

【问题讨论】:

    标签: cql ndepend


    【解决方案1】:

    使用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 }
    

    【讨论】:

    • Patrick 谢谢你的逻辑......但同样的限制是我试图对程序集 a 中的所有方法执行此操作,以了解程序集 a 中的每个方法在程序集 b 中调用方法本身。 ..换句话说,如何使所有方法都递归...结果也应该是程序集a中的方法a和程序集b中的调用方法之间的映射。
    • Patrick..感谢更新..我会试试这个查询,让你知道它是怎么回事..!谢谢!
    猜你喜欢
    • 2012-06-16
    • 2011-02-03
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    相关资源
    最近更新 更多