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

1

6

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.

Tasha answered 4/8, 2015 at 20:15 Comment(0)
H
4

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

Hyponitrite answered 5/8, 2015 at 14:9 Comment(1)
Thanks, I'll download the trial and see how it goes.Tasha

© 2022 - 2024 — McMap. All rights reserved.