我们的代码库非常庞大,多个团队拥有不同的层。一个团队想知道正在调用什么方法和类型,以便他们可以集中它们。因此,对于我们放入NDepend项目中的一组DLL和可执行文件,什么查询将为我们提供所有使用的方法,这些方法都包含在以'Company.ODS'开头的程序集中。
答案 0 :(得分: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 }