Inherited Method Dependencies Using NDepend

The NDepend class browser doesn't seem to have the ability to expose inherited methods .

We have a scenario where we have thousands of single root Model objects that, for example, descend from the RootModel . Only RootModel defines Save () . How to form a query to find all instances where SampleModel (: RootModel) calls Save () ?

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

      

... rejected: Invalid assembly, namespace, type, method, or field name .

This seems to be the best approximation, but not accurate:

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

      

It sounds like a pretty heavy limitation, no? What's the workaround?

+2


source to share


1 answer


From a static point of view, the NDepend class SampleModel

does not declare a method Save()

. This is why the first request does not compile.

The second query is really good in your case. To get things right, you can use Code Query in LINQ (CQLinq features) and rewrite it like this:



from m in Application.Types.Where(t => t.DeriveFrom("MyNamespace.RootModel"))
         .ChildMethods()
where m.IsUsing("MyNamespace.RootModel.Save()")
select new { m, m.ParentType }

      

+1


source







All Articles