Groups | Blog | Home
all groups > dotnet clr > july 2004 >

dotnet clr : Determine calling method from within called method?


Ben Fidge
7/23/2004 7:24:46 AM
From within a method of a class, how do you determine the
name of the class.method that called it, programmatically?

I have a log file class, and it would be very beneficial
to be able store the name of the class and method that
called my LogFile.Write method.

Kind regards

Ben
Christopher Wells
7/23/2004 11:33:58 AM

[quoted text, click to view]

Perhaps the System.Diagnostics.StackTrace class is what you want.

Sridhar
7/23/2004 2:00:03 PM
Hi,

May be You can use

System.Reflection.MethodBase.GetCurrentMethod().DeclaringType which will give the class name from which it is called.

Sridhar!!


[quoted text, click to view]
ataleb NO[at]SPAM microsoft.com
7/26/2004 4:01:50 PM
You can use System.Diagnostics.StackTrace to get the calling method using
GetFrame method.
AddThis Social Bookmark Button