Walking the function stack --- Reflection question.

  • Thread starter Thread starter Tim Burda
  • Start date Start date
T

Tim Burda

I know you can use the property
System.Reflection.MethodInfo.GetCurrentMethod().Name to get the name
of the function currently be executed.

What I want to do is get the name of the function which called the
function I am currently in.

For example (pardon my pseudo-code):

public void ABC()
{
// Do some stuff here

XYZ();
}

public void XYZ()
{
//I want to determined the name of the function that called XYZ.
//In this case, ABC

}

Any thoughts???

Thanks -

Tim Burda
(e-mail address removed)
 
StackTrace st = new StackTrace ()
if ( st.FrameCount > 0 )

StackFrame sf = st.GetFrame (i)
Debug.WriteLine ( sf.GetMethod ())


HT

Rafat Sarosh
 
Rafat Sarosh said:
StackTrace st = new StackTrace ();
if ( st.FrameCount > 0 )
{
StackFrame sf = st.GetFrame (i);
Debug.WriteLine ( sf.GetMethod ());
}

HTH

Rafat Sarosh

Thanks to all who responded, I have solved the initial problem, but
now let's say I passed a parameter to the function. I can easily the
get name and type of the parameter, but in the ParameterInfo object, I
don't see a way to get the value.

Is this possible?
 
Tim Burda said:
Thanks to all who responded, I have solved the initial problem, but
now let's say I passed a parameter to the function. I can easily the
get name and type of the parameter, but in the ParameterInfo object, I
don't see a way to get the value.

Is this possible?

No, it's not.
 
Back
Top