通过NDepend规则构建依赖关系路径

时间:2016-12-08 09:52:47

标签: path dependencies ndepend cqlinq

我可以使用CQLinq / NDepend找到间接依赖关系,并使用魔术“FillIterative”-Method我可以过滤找到的依赖关系。之后访问“DefinitionDomain”可以为我提供依赖路径的深度(跳数)。

我现在的问题是: 我可以以某种方式添加依赖路径到我的查询结果中的每个条目?因此,对于查询成员“目标”的所有间接使用以及使用深度的查询,而不是表单的结果

method          depth
------------------------------------------------------------------------
Foo             2
Bar             1
Baz             0

我会得到表单的结果

method          depth          path
------------------------------------------------------------------------
Foo             2              Foo, Something1, Something2, Target
Bar             1              Bar, Something3, Target
Baz             0              Baz, Target

......这可能吗?

编辑:到目前为止,这是我的查询:

// <Name>Async methods must not use non-async variants of EnsureInThisCtx methods, even indirectly</Name>
warnif count > 0
let mse = Methods.WithFullNameLike("DbContext\\.EnsureIsInThisCtx[^A]")
let m1 = mse.First()       // there are two overloads
let m2 = mse.ElementAt(1)  // of the method I want to catch.
let icd1 = m1.ToEnumerable().FillIterative(methods => methods.SelectMany(m => m.MethodsCallingMe.Union(m.OverriddensBase)))
let icd2 = m2.ToEnumerable().FillIterative(methods => methods.SelectMany(m => m.MethodsCallingMe.Union(m.OverriddensBase)))
let hits1 = (from m in icd1.DefinitionDomain where m.IsAsync select m)
let hits2 = (from m in icd2.DefinitionDomain where m.IsAsync select m)
from m in hits1.Union(hits2).Distinct()
let dist1=icd1[m]
let dist2=icd2[m]
select new { m, DepthOfUsageVariant1=dist1, DepthOfUsageVariant2=dist2 }

示例输出如下所示:

methods         DepthOfUsageVariant1  DepthOfUsageVariant2
------------------------------------------------------------------------
Foo             2                     0
Bar             0                     1
...

0 个答案:

没有答案