I have a function called RegisterXX. Its called from a bunch of places. I
need to know the method name that is calling my RegisterXX
for example given the following code:
public void MyFunctionA
{
//... do something
RegisterXX();
}
public void MyFunctionB
{
//... do something
RegisterXX();
}
I'm trying to hook up some instrumentation code in RegisterXX and want to be
able to pull the caller's name out of the air so I don't have to rely on
developers hooking things up correctly.
public void RegisterXX( EventTypeEnum eventType )
{
string s_MethodName = GetCallingMethodName();
WriteOutInstrumentation( s_MethodName, eventType );
)
so when MyFunctionA calls the RegisterXX method some instrumentation data is
written with the name "MyFunctionA".
I'm trying to be extremely clear here. I just need to know how to find the
calling method.
Hi,
look at StackTrace and StackFrame classes.
Sunny
> I have a function called RegisterXX. Its called from a bunch of places. I
> need to know the method name that is calling my RegisterXX
[quoted text clipped - 28 lines]
> I'm trying to be extremely clear here. I just need to know how to find the
> calling method.
Hi,
Here is an example, you may take a look.
StackTrace Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdiagnosticsstacktraceclasstopic.asp
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Yes, I could do that. I believe its pretty expensive from a perf
perspective. Isn't there something cheaper?
> Hi,
>
> Here is an example, you may take a look.
> StackTrace Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemdiagnosticsstacktraceclasstopic.asp
>
[quoted text clipped - 5 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 16 Jul 2004 08:55 GMT
Hi,
Because get the calling method will need walk the call stack, and the
StackTrace is the managed class for the purpose.
Another way is to log the calling method name in a global variable every
you invoke a call, which may somewhat complicated.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Richard Blewett [DevelopMentor] - 12 Sep 2004 08:10 GMT
System.Diagnostics.StackFrame s= new System.Diagnostics.StackFrame(1); s.GetMethod().Name;
HTH
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
?
nntp://news.microsoft.com/microsoft.public.dotnet.framework/
Hi,
Here is an example, you may take a look.
StackTrace Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdiagnosticsstacktraceclasstopic.asp
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
[microsoft.public.dotnet.framework]