"Nick Hall" <ni***@aslan.nospam.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Don" <un*****@oblivion.com> wrote in message
news:F7PQd.409202$Xk.355732@pd7tw3no... This may seem like an odd question, but is it possible to get the name
of the class & function that is calling a function of another class?
Have a look in the System.Diagnostics namespace at the classes StackTrace
and StackFrame. The StackTrace will allow you to obtain a reference to
the StackFrame above the current one (i.e. the calling method). You can then
obtain a System.Reflection.MethodBase which will contain all the
information you need. Note, this will probably only work as expected in Debug builds
(as the naming information is not available in Release builds).
Thanks for the tips. Here's what I ended up doing (more or less):
Dim strace As New StackTrace
Dim frame As New StackFrame
Dim method As System.Reflection.MethodBase
frame = strace.GetFrame(1) ' Gets the stack frame for the method that called
this one
method = frame.GetMethod ' Grab method info
Console.WriteLine(method.ReflectedType.Namespace & "." &
method.ReflectedType.Name & "." & method.Name)
- Don