Is there some tool which can somehow extract into a file or files all the dependencies related to a given function or class.

I have often had to do this and have not found a satisfactory solution. I currently use JetBrains Resharper and specifically View Type Depencies in version 9, but even in simple cases you still have to then navigate to each dependency and copy the code. The NDepend tool is also helpful but does not perform the task completely.

The motivation for this is being able to extract a small part of code to port into another project in cases where the projects are independent, and we do not want to create dependencies between the projects. I realize that this duplicates code in the code base(s) BUT there are definitely legitimate needs for this!

(ideally free /open source but even commercial would be great)

There are lots of tools available for the specified task. Visual Studio 2013/2015 comes built on with this feature set but it displays the basic ones only. If you want the whole complete set of the references I recommend you to use the Visual Studio Productivity Power Tools. It is available inside the extension managers in visual studio or you can download as an extension from the browser.

but I must warn you that these extensions in the development environment causes a lag in the GUI

  • 1
    these extensions look powerful but I don't see the function to extract dependent code. – shev72 Apr 15 '16 at 8:26
  • I guess all tools I have come across do need some manual intervention to complete, just makes a lot of things easier. – Dilip Apr 15 '16 at 8:46

I would suggest running DoxyGen in Java/C# mode on the original code with the inline sources and references relation turned on.

This will generate a set of web pages which you can navigate to the method in question and simply follow the dependencies with the code for them displayed in the browser, ready to copy and paste.

  • Free, Gratis & Open Source
  • Cross Platform
  • No risk of damaging the original code, I have seen people dragging code from one window to another and accidentally removing code from the parent project
  • No IDE slowdown
  • Documents the original code
  • Sometimes highlights unexpected problems in the original code
  • 1
    I love Doxygen, but the issue is the same as the one in my question, I would have to navigate the whole tree and copy the sources one by one. – shev72 Apr 15 '16 at 7:40
  • @shev72 I think doxygen might give some good starting point, doxygen can output in xml format (GENERATE_XML=YES) and when setting also REFERENCED_BY_RELATION=YES and / or REFERENCES_RELATION=YES you get the found references in the xml files. You could parse these files and get values from it. – albert Aug 8 at 13:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.