Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a VS2010 Add-In in C#, how do you get the name and signature of the method your cursor is currently in?

In a VS2010 Add-In in C#, how do you get the name and signature of the method your cursor is currently in?

I want to create an add-in that when run, gets the name and signature of the current method and then adds an "in" and "out" log message for that method.

Example:

Before:

public void TheMethod(string text)
{
...

return text;
}

After:

public void TheMethod(string text)
{
log.Trace("public void TheMethod( string text =" + text + " ) - in");

...

log.Trace("public void TheMethod( ... ) - out with text = " + text );

return text;
}

Are there any add-in tutorials/links that cover getting method info, seeing the top and bottom of a method, inserting text, etc? I've tried Googling and I'm not getting myc that's helpful.

like image 273
Eric Brown - Cal Avatar asked Dec 27 '25 14:12

Eric Brown - Cal


2 Answers

Addressing your logging requirement specifically, this is the sort of thing that Aspect Oriented Programming is suited for. PostSharp, for example, can do the kind of boundary actions you're looking for. See here for an example of how this is done with that framework.

like image 56
mwilson Avatar answered Dec 31 '25 18:12

mwilson


You might want to consider something called an Aspect Oriented approach. See Aspect Oriented Programming: When to start using a framework? for a good start.

like image 27
Digbyswift Avatar answered Dec 31 '25 18:12

Digbyswift