Programmatically Determine Method Name?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdebug' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Steven A Smith (VIP)
In a Trace.Write() statement, is it possible to dynamically determine the
current method's name and/or signature? I'm using this to get the current
object:
this.GetType().ToString() + ".CreateChildControls()

But I'd like to replace the hardcoded ".CreateChildControls()" with something
automatic (to make it easier to cut and paste). Does such a call exist?

Also, is there a way to get the current class's type? Right now I'm using
GetType() as you can see, but that returns the variable's type. I want my
class's type (which may or may not be the same thing due to inheritance). For
instance if I have a Person class and a Customer class, both of which have the
same method Foo() (Customer overrides Person), I want Customer.Foo() and
Person.Foo() to show up in my trace statement.

Thanks,

Steve

Reply to this message...
 
    
Scott (VIP)
Here you go:

Dim st As New System.Diagnostics.StackTrace()
Dim sf As System.Diagnostics.StackFrame =3D st.GetFrame(0)
MessageBox.Show(sf.GetMethod().Name)

[Original message clipped]

Reply to this message...
 
    
Steven A Smith (VIP)
Perfect, thanks.

Can you tell which class that's coming from?

e.g. if I have Class Person and Class Customer and both have a getName function,
and Customer calls MyBase.getName() so both get called whenever one is called,
is there a programmatic way for me to see *which* getName I'm in?

I've been using GetType().ToString() but that always shows the instance's class
(Customer, not Person), regardless of how deep into the object parent tree the
method calls go.

Thanks!
Steve

----- Original Message -----
From: "Scott" <Click here to reveal e-mail address>
To: "aspngdebug" <Click here to reveal e-mail address>
Sent: Wednesday, January 30, 2002 5:43 PM
Subject: [aspngdebug] RE: Programmatically Determine Method Name?

Here you go:

Dim st As New System.Diagnostics.StackTrace()
Dim sf As System.Diagnostics.StackFrame = st.GetFrame(0)
MessageBox.Show(sf.GetMethod().Name)

[Original message clipped]

| [aspngdebug] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdebug.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.Diagnostics.StackFrame
System.Diagnostics.StackTrace
System.Diagnostics.Trace
System.Windows.Forms.MessageBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com