【问题标题】:NDepend query to detemine what methods in other DLLs are being calledNDepend 查询以确定正在调用其他 DLL 中的哪些方法
【发布时间】:2018-08-23 16:53:46
【问题描述】:

我们有一个非常庞大的代码库,其中多个团队拥有不同的层。一个团队想知道调用了哪些方法和类型,以便他们可以集中它们。因此,对于我们放入 NDepend 项目中的一组 DLL 和可执行文件,什么查询会为我们提供所有方法,这些方法会使用并包含在以名称“Company.ODS”开头的程序集中。

【问题讨论】:

  • 请详细说明您要达到的目标。谢谢。
  • 同样,我们有一组 DLL 和可执行文件 - 我们想知道 Company.ODS 程序集中包含的该组中使用的每个方法和类型。例如,装配订单有调用方法 Inventory.Save 和 Inventory.Change。这两种方法在程序集 Company.ODS 中定义。我希望我的结果集中有这些方法。

标签: ndepend


【解决方案1】:

有两种方法可以编写此查询。

在这两种情况下,let assembliesUsed = Application.Assemblies.WithNameIn("Infrastructure", "ApplicationCore") 都是适应您的代码的部分,例如 let assembliesUsed = Assemblies.Where(a => a.Name.StartsWith("CompanyName.Feature"))


A) 使用类型/方法/字段使用呈现结果。

let assembliesUsed = Application.Assemblies.WithNameIn("Infrastructure", "ApplicationCore")

let typesUsed = assembliesUsed.ChildTypes().ToHashSetEx()
let membersUsed = assembliesUsed.ChildMembers().ToHashSetEx()

let typesUser = Application.Types.UsingAny(typesUsed).Where(
  t => !assembliesUsed.Contains(t.ParentAssembly))

let methodsUser = Application.Methods.UsingAny(membersUsed).Where(
  m => !assembliesUsed.Contains(m.ParentAssembly))

from x in assembliesUsed.ChildTypesAndMembers()
let users = 
  x.IsMethod ? x.AsMethod.MethodsCallingMe.Intersect(methodsUser).Cast<IMember>() : 
  x.IsField ?  x.AsField.MethodsUsingMe.Intersect(methodsUser).Cast<IMember>() : 
               x.AsType.TypesUsingMe.Intersect(typesUser)
where users.Any()
select new { x, users }


B) 使用类型/方法用户呈现结果。

let assembliesUsed = Application.Assemblies.WithNameIn("Infrastructure", "ApplicationCore")

let typesUsed = assembliesUsed.ChildTypes().ToHashSetEx()
let membersUsed = assembliesUsed.ChildMembers().ToHashSetEx()

let typesUser = Application.Types.UsingAny(typesUsed).Where(
  t => !assembliesUsed.Contains(t.ParentAssembly))

let methodsUser = Application.Methods.UsingAny(membersUsed).Where(
  m => !assembliesUsed.Contains(m.ParentAssembly))

from x in methodsUser.Concat<IMember>(typesUser)

let used = 
  x.IsMethod ? x.AsMethod.MembersUsed.Intersect(membersUsed) : 
               x.AsType.TypesUsed.Intersect(typesUsed) 
where typesUsed.Any()
select new { x, used }

【讨论】:

  • 这似乎返回了调用 Company.ODS 中方法的方法,我们想要从项目中的 DLL 调用的 Company.ODS 方法的列表。我想要单击“已使用”列中的项目时得到的结果。您可以在上面为 ApplicationCore 提供的屏幕截图中看到这一点。我想获取唯一列表并将其导出到 Excel。当我从某个地方(即网页、注释)剪切并粘贴到查询文本框中时,我看到的另一个问题很烦人,文本消失并留下一个红色框。然后我需要手动输入查询。
猜你喜欢
  • 1970-01-01
  • 2011-02-03
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多