Managed Space : Jason Whittington's Radio Weblog

Updated: 3/26/2003; 9:19:45 AM.DevelopMentor

 

Subscribe to "Managed Space" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, December 27, 2002

This doesn't look like Kansas...

I try to resist just parroting other people's posts, but this one is too cool. If the StackTrace and StackFrame classes picque your interest then I highly recommend looking at the Rotor sources - there's some pretty neat stuff in there.  [From Sean and Scott - you are subscribed, right?]

Question : How do you get the name of the executing method/name of the method that called you/name of the type your in, etc?

Answer:

System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
System.Diagnostics.StackFrame sf = st.GetFrame(0);
MessageBox.Show(sf.ToString());
If you just want the name of the method, then the GetMethod method return a MethodInfo object, so you can just say :
MessageBox.Show(sf.GetMethod().Name);

To get to the type, it's just:

MessageBox.Show(sf.GetMethod().ReflectedType.ToString());

1:42:46 PM      comment []

© Copyright 2003 Jason Whittington.



Click here to visit the Radio UserLand website.

 


December 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Nov   Jan

Stuff I recommend:
.NET Resources
COM/C++ Resources
Fun stuff
Stuff I've done:
Windows/COM
.NET
Writings
Conferences

Stuff I read: