juin 12

Recently I have been in the need of extracting  kind of a "call tree" of some functions of my code.

More exactly, it was not such the call tree, but I was needing to be able to list of methods being called by a given entry point, and then seeing the size of each tree.

NDepend can very easily give this information. Let's see how !

Let's start with code

Let's write some code that we'll use to validate our results. We'll start with a very basic set of class that will call each other:

namespace ClassLibrary1
   public class SecondClass
      public void DoInSecondClass()
      public void DoInSecondClass_NoPrivate() { }
      private void PrivateMethod() { }
   public class TopClass
      public void Do()
      private void FirstMethod()
         SecondClass obj = new SecondClass();
      private void SecondMethod()
         SecondClass obj = new SecondClass();

Let's create our NDepend project

Our project is very basic but should be enough to validate our results. So now, we will create our NDepend project to start collecting (and validating) our metrics.

  • Start NDepend
  • Click on "Home / Start" and choose "New Project"
  • Give a project name ("NDepend Test" for instance) and the location where you want to store it
  • In the Code to Analyse tab, click on Add assemblies of a Visual Studio Solution and select the project you have just created.
  • In the Report tab, click on Select All

And here you are, ready to start the analysis ! Just click on Run Analysis and wait for NDepend to prompt the report.

Let's dig into the called method

We now want to find all the methods called by our entry point.

At the end of the analysis, NDepend pops up the report in your favorite browser. However, we'll close it for now and we will search our entry point in the Class Browser. To do that, either use the Show Menu button in the menu, or the hotkey ctrl + alt + C.

Just select the method you want, right-click on it, and select Who I use indirectly and then SELECT METHODS WHERE ...

Click on the image to enlarge

What happens here ? NDepend will generate for us a CQL Query. A CQL Query is written using the CQL language, a SQL-like language that allows us to run queries against our code to extract some information, statistics, .... Here we are using the following query :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy

When we look to the result, it looks pretty good, unless that we do not have the number of line of code. Easy. We can just update the CQL Query like that :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy, NbLinesOfCode

and here the result we get :

Of course the last column is visible only because we have altered the query to add another ORDER BY clause

Any graphical representation ?

It would be very nice to be able to extract a visual call tree with all the methods we have here in the CQL result. And of course, this can be done easily. Just go to the CQL Query Result page and right clic on the line marked 8 methods matched. Then you can choose Export 8 methods matched to Graph

Click on the image to enlarge

Antyhing missing ?

What we have here is pretty cool to find quickly information and in our case the dependencies between methods. Anyway, there is a functionality that could be nice to be added on the graph. We may start viewing a graph not from a CQL Query result, but from a list of assemblies. And thus it could be interesting to be able to :

  • From a graph of assemblies dependencies : doing a zoom meaning double-clicking on an assembly to see the type dependencies of that assembly
  • On a type, being able to do a zoom, meaning double-clicking on the type to see the method dependencies of that type
  • On a mehtod being able to right-clic to add to the graph or the callers, or the callees


 Anyway, even if some functionalities could be added to the tool, NDepend is a very interesting tool, easy to learn and very powerful - especially due to the CQL language.

Give it a try, and comment about our use !


Patrick Smacchia

Posted on lundi, 15 juin 2009 10:32

Hi these are possible:
>From a graph of assemblies dependencies : doing a zoom meaning double-clicking on an assembly to see the type dependencies of that assembly

and then export the result to the graph

>On a type, being able to do a zoom, meaning double-clicking on the type to see the method dependencies of that type

right click the type and do: View internal dependencies on Graph

>On a method being able to right-clic to add to the graph or the callers, or the callees

Right click the method, select: who is indirectly using me? / who I use indirectly?
and then export the result to the graph

More dependencies scenario exposed in these 2 posts:


Posted on vendredi, 24 juin 2011 08:41

<a href="www.ilife100.com/.../EditDaily.aspx?id=2614" >burberry</a>    <a href="www.ime366.com/.../...do-thread-id-9185.html" >burberry</a>    <a href="www.isee.com.cn/plus/view.php?aid=11175" >burberry</a>    <a href="www.i-sleepy.org/.../space.php >burberry</a>    <a href="www.ilaobing.com/home.php >burberry</a>    <a href="http://www.igo668.com/plus/view.php?aid=8228" >burberry</a>    <a href="www.ige8.com/.../home.php >burberry</a>    <a href="http://www.idea110.com/bbs/blog.asp?id=792" >burberry</a>    <a href="www.hsjq.com/.../boke.asp >burberry</a>    <a href="http://www.hxqc.cn/bbsxp/blog.asp?id=15602" >burberry</a>    <a href="http://www.hy8283.com/plus/view.php?aid=1365" >burberry</a>    <a href="http://www.hwbb99.com/blog.asp?id=2623" >burberry</a>    <a href="www.hw0001.com/.../boke.asp >burberry</a>    <a href="www.huanlegumenpiao.com/.../view.php >burberry</a>    <a href="www.huanavip.com/.../boke.asp >burberry</a>    <a href="www.huagangss.com/luntan/blog.asp?id=6228" >burberry</a>    <a href="www.ht2ht.com/.../boke.asp >burberry</a>    <a href="www.hnaqw.com/.../home.php >burberry</a>    <a href="www.hncdgy.com/.../boke.asp >burberry</a>    <a href="http://www.hnjgy.com/plus/view.php?aid=4641" >burberry</a>    <a href="www.hnmst.com/.../boke.asp >burberry</a>    <a href="www.hongren5.com/plus/view.php?aid=13294" >burberry</a>    <a href="http://www.hebcch.org.cn/bbs/blog.asp?id=94" >burberry</a>    <a href="http://www.hlj56.com/bbsxp/blog.asp?id=1136" >burberry</a>    <a href="http://www.hkjsjx.com/plus/view.php?aid=1177" >burberry</a>    <a href="www.hhkao.com/apps.php >burberry</a>    <a href="www.guangshuishi.com/.../boke.asp >burberry</a>    <a href="www.gzba.org/.../boke.asp >burberry</a>    <a href="www.hangmo.net.cn/plus/view.php?aid=11672" >burberry</a>    <a href="www.greenwx.com/space.php >burberry</a>    <a href="www.hfsjs.com/home.php >burberry</a>    <a href="http://www.gpsjx.com/bbs/blog.asp?id=4959" >burberry</a>    <a href="www.giswill.com/home.php >burberry</a>    <a href="www.fzuc.com/home.php >burberry</a>    <a href="www.gcszy.com/.../boke.asp >burberry</a>    <a href="www.fy168.cc/...-251927-do-blog-id-6449.html" >burberry</a>    <a href="www.ebulent.com.cn/.../blog.asp?id=1472" >burberry</a>    <a href="www.ef-life.com/...2277-do-blog-id-2587.html" >burberry</a>    <a href="www.emba.com.cn/.../space.php >burberry</a>    <a href="www.englishunion.com/plus/view.php?aid=39949" >burberry</a>    <a href="www.fadaiwang.com/space.php >burberry</a>    <a href="bbs.df123.net/fghfgh.showtopic.11268.html" >burberry</a>    <a href="www.dj45678.com/.../space.asp >burberry</a>    <a href="www.dj-bb.cn/.../space.asp >burberry</a>    <a href="www.dreamocean.com.cn/bbsxp/blog.asp?id=5635" >burberry</a>    <a href="www.dwxyzh.com/plus/view.php?aid=297472" >burberry</a>    <a href="www.cyberman.cn/bbsxp/blog.asp?id=8037" >burberry</a>    <a href="www.dazhemusic.com/plus/view.php?aid=11256" >burberry</a>    <a href="http://www.czcanyin.com/bbs/blog.asp?id=1116" >burberry</a>    <a href="www.cuijianchi.com/boke.asp >burberry</a>    <a href="www.ctzxyy120.com/ww/bbs/blog.asp?id=8692" >burberry</a>

Naturlakemedel Impotens Botemedel

Posted on mardi, 20 août 2013 23:35

Howdy! This article could not be written much better! Looking at this post reminds me of my previous roommate! He constantly kept talking about this. I will send this article to him. Pretty sure he's going to have a very good read. Many thanks for sharing!

my webpage -  Naturlakemedel Impotens Botemedel - wehelpbuyinshop.com/kopforzestutanreceptse1/

Ajouter un commentaire

  • Commentaire
  • Aperçu immédiat