我正在尝试用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它应该列出不符合接口隔离原则的类型。
谢谢!
发布于 2013-01-21 08:51:17
因此,您所请求的查询可以这样编写:
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不为空时匹配一次。然后,结果被很好地呈现出来,并且可以理解:

https://stackoverflow.com/questions/14415818
复制相似问题