ndepend - NDepend 查询以确定正在调用其他 DLL 中的哪些方法
问题描述
我们有一个非常大的代码库,多个团队拥有不同的层。一个团队想知道调用了哪些方法和类型,以便他们可以集中它们。因此,对于我们放在 NDepend 项目中的一组 DLL 和可执行文件,什么查询会为我们提供所有方法,这些方法将被使用并包含在以名称“Company.ODS”开头的程序集中。
解决方案
有两种方法可以编写此查询。
在这两种情况下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 }
推荐阅读
- python - 如何优化当前使用列和行迭代完成的 python 数据帧上的多个操作?
- python - 过滤整个相关矩阵的值
- javascript - 如何从自定义挂钩验证中正确显示错误消息?
- groovy - 在groovy中打印包含特定扩展文件的文件夹
- sql - 相同的表,SQL Server 查询中的不同性能
- kubernetes - Kubernetes env 变量在 sequelize-cli 中不起作用
- uml - PlantUML 组件图表端口
- z3 - Z3Py 中 (assert (= a 10)) 的等价物
- ios - iOS 13:使用 UINavigationBarAppearance 时忽略 NavigationBarBarStyle
- amazon-web-services - 使用 CloudFront 签名 URL 使用 Imagemagick 编码图像