Inherited method dependencies using NDepend

The class browser of NDepend doesn't seem to have an option for revealing inherited methods .

We have a scenario where we have thousands of singly-rooted Model objects that descend from RootModel , for instance. Only RootModel defines Save() . How does one form a query for finding all instances where SampleModel (:RootModel) invokes Save() ?

SELECT METHODS WHERE IsUsing "SampleModel.Save()" ORDER BY DepthOfIsUsing

...is rejected: Not a valid assembly, namespace, typ, method or field name .

This seems to be the best approximation but is not exact:

SELECT METHODS WHERE IsUsing "SampleModel" AND IsUsing "RootModel.Save()" ORDER BY DepthOfIsUsing

This seems like a pretty heavy limitation, no? What's the workaround?


From the static point of view of NDepend the class SampleModel doesn't declare a Save() method. This is why the first query doesn't compile.

The second query is indeed the good thing to do in your case. To get it right, you can use the Code Query on LINQ (CQLinq capabilities) and rewrite it this way:

from m in Application.Types.Where(t => t.DeriveFrom("MyNamespace.RootModel"))
         .ChildMethods()
where m.IsUsing("MyNamespace.RootModel.Save()")
select new { m, m.ParentType }
链接地址: http://www.djcxy.com/p/37728.html

上一篇: 排除大会在某些方面,但不是其他人

下一篇: 使用NDepend继承的方法依赖关系