5

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)

2 Answers 2

1

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
2
  • 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. Commented Apr 15, 2016 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
    Commented Aug 8, 2018 at 13:17
0

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

2
  • 1
    these extensions look powerful but I don't see the function to extract dependent code. Commented Apr 15, 2016 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
    Commented Apr 15, 2016 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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