Reputation: 14389
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.
Upvotes: 3
Views: 221
Reputation: 10400
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.
Upvotes: 1
Reputation: 1285
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.
Upvotes: 1