Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NDepend output code in all methods up the dependency tree for specific methods?

Tags:

c#

ndepend

I’m looking to be able to integrate into our build process the ability to compare after each build against the prior build any code changes made on any dependencies for a list of specific methods.

So, if I have two methods that access the database, I want to be able to tell if any method that called either of these two methods, all the way up the dependency tree have had any code changes.

like image 512
David Penn Avatar asked Aug 04 '15 20:08

David Penn


1 Answers

Such code query should answer your need:

// <Name>Methods that call Parse(String) or get_TestName() and that was added or where cpde was changed</Name>
from m in Methods 
let depth0 = m.DepthOfIsUsing("NUnit.Core.RuntimeFramework.Parse(String)")
let depth1 = m.DepthOfIsUsing("NUnit.Core.Test.get_TestName()")
where (depth0  >= 0 || depth1 >= 0)
   && (m.CodeWasChanged() || m.WasAdded())

orderby (depth0 != null ? depth0 : depth1)
select new { m, depth0, depth1  }

Of course with the prefix warnif count > 0 you can transform it into a rule if you wish.

Here is this code query in action, underline methods are the ones where code was changed since baseline, methods in bold are the ones added since baseline.

NDepend calls in dependency tree diff methods

You can right click an underlined methods to ask to see diff in source code with your preferred diff tool.

You can also export the result to a graph (button Export to Graph) but then you might get disjoint graphs, since methods unchanged will be missing:

enter image description here

like image 161
Patrick from NDepend team Avatar answered Oct 18 '22 01:10

Patrick from NDepend team