1

我正在尝试使用 NDepend 创建一个特殊查询,但无法弄清楚。

这是我想用更程序化的伪代码查询的内容:

var list
foreach type t
    foreach i = t.attribute that is an interface
        var nm = i.numberOfMethods
        var mu = numberOfMethods that t actually uses
        if mu / nm < 1
        list.Add(t)
    end foreach
end foreach
return list

它应该列出不符合接口隔离原则的类型。

谢谢!

4

1 回答 1

2

所以你问的查询可以这样写:

from t in JustMyCode.Types where !t.IsAbstract

from i in t.TypesUsed where i.IsInterface

// Here collect methods of i that are not used
let methodsOfInterfaceUnused = i.Methods.Where(m => !m.IsUsedBy(t))
where methodsOfInterfaceUnused.Count() > 0
select new { t, methodsOfInterfaceUnused }

该查询的特点是多次匹配同一个类型,每次匹配一个methodsOfInterfaceUnused不为空。结果很好地呈现并且易于理解:

NDepend 的隔离原理

于 2013-01-21T00:51:17.437 回答