查询以检测ISP违规

时间:2013-01-19 15:27:01

标签: ndepend

我正在尝试使用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

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

谢谢!

1 个答案:

答案 0 :(得分: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 }

此查询具有匹配多个时间相同类型的特性,每次{1}}不为空。结果很好地呈现并且可以理解:

Segregation Principle with NDepend