Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

Identifying the Method Name Calling Your Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
- 14 Jul 2004 19:15 GMT
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.
Sunny - 14 Jul 2004 20:13 GMT
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.
"Peter Huang" - 15 Jul 2004 02:42 GMT
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.

- 16 Jul 2004 02:49 GMT
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]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.