Finding procedure callers

  • Thread starter Thread starter Chris Dunaway
  • Start date Start date
C

Chris Dunaway

If you right click on a variable, sub, or function name and choose 'Go
to Definition', it will take you to the code for that item.

What I would like to be able to do is right click on a sub or function
declaration and have it display a list of places in my project where
that is being called from.

I figure I would need a macro to do this but what namespaces
(Reflection? etc.) would be used to determine the callers of a method?

Thanks,
 
Chris Dunaway said:
If you right click on a variable, sub, or function name and choose 'Go
to Definition', it will take you to the code for that item.

What I would like to be able to do is right click on a sub or function
declaration and have it display a list of places in my project where
that is being called from.

I figure I would need a macro to do this but what namespaces
(Reflection? etc.) would be used to determine the callers of a method?

Thanks,

It would only be practical to show all places in the current project or
solution. It would be impossible (at least improbable) to show all
occurances in compiled assemblies. You would basically have to perform a
manual search, making a note of every var that is the same type, or a
child/grandchild/et cetera of that type. You'll have to make sure it is not
being over-ridden in those children, then perform you search based on those
criteria.

Long process, unless you have a lot of time to do this, maybe you should
re-think doing it altogether?
Mythran
 
There is a product called MZTools for VB6 that already has this
feature. I want the information at *design* time.

MZTools is available for .Net but that version is not free. I was
hoping to learn a little about the CodeDOM and see if that would help
me accomplish the task.

Thanks for the reply
 
Hi Chrish,

Given a class, say "MyClass" and a sub, say "MySub", first, you need to
search occurrences of the sub name in your whole class, file, project source
code, or referencing projects in a solution, depending on the scope of your
sub. That's the easy part. The tricky part is to resolve if the class object
returned by the below expression refers to "MyClass" or some other class
which happens to have also a "MySub" procedure:

MyObj.Myf1.MyProperty.Items(3).MySub

So, you have to parse the source code, walking inside assemblies using
Reflection, or both, to resolve each part of the expression of an
occurrence. Believe me that it will take you weeks of work to do it
properly. I did it for MZ-Tools 4.0, and while it is no longer freeware, I
think it's quite cheap for the value that you receive, not only for that
feature.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Carlos said:
think it's quite cheap for the value that you receive, not only for that
feature.

I certainly agree and may yet purchase it, but I was wondering what
framework classes, if any, existed to help accomplish this task.
 
You can temporary rename your sub-name to xxx_mysub and then you will
see in the task list all the code references that now can not find the
original sub-name.

This work for the currnt project only.
This might not work when sub-name is overloaded, inherited, etc...

Atara
 
Hi Chris,

- To parse the source code, the extensibility model of VS.NET for add-ins
(EnvDTE assembly) provides functions to get the code elements (namespaces,
classes, class variables, procedures, parameters and so on), but, alas, it
does not retrieve procedure variables, so you have to parse the code
yourself.

- To walk into compiled assemblies, you have to use Reflection.

If you want to get started with add-ins, I have compiled a long list of
resources on my web site:

http://www.mztools.com/resources_addin_developers.htm

Also, you can contact me for specific questions about add-ins or use a more
appropriate newsgroup (the link above lists the best ones).

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top