Walking the function stack --- Reflection question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Burda

    Walking the function stack --- Reflection question.

    I know you can use the property
    System.Reflecti on.MethodInfo.G etCurrentMethod ().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
    Tim.Burda@si-intl.com
  • Jan Tielens

    #2
    Re: Walking the function stack --- Reflection question.

    This could be possible usint the StackTrace class in the System.Diagnost ics
    namespace. There is a nice article about this topic on the CodeProject:



    --
    Greetz,
    Jan
    _______________ _______________ ____
    Read my weblog: http://weblogs.asp.net/jan
    "Tim Burda" <Tim.Burda@si-intl.com> schreef in bericht
    news:bc56d0ed.0 312050913.61e75 5fa@posting.goo gle.com...[color=blue]
    > I know you can use the property
    > System.Reflecti on.MethodInfo.G etCurrentMethod ().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
    > Tim.Burda@si-intl.com[/color]


    Comment

    • Rafat Sarosh

      #3
      RE: Walking the function stack --- Reflection question.

      StackTrace st = new StackTrace ()
      if ( st.FrameCount > 0 )

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


      HT

      Rafat Sarosh

      Comment

      • Tim Burda

        #4
        Re: Walking the function stack --- Reflection question.

        Rafat Sarosh <anonymous@disc ussions.microso ft.com> wrote in message news:<8EA717DF-8236-4F2F-8F5B-0477033287F9@mi crosoft.com>...[color=blue]
        > StackTrace st = new StackTrace ();
        > if ( st.FrameCount > 0 )
        > {
        > StackFrame sf = st.GetFrame (i);
        > Debug.WriteLine ( sf.GetMethod ());
        > }
        >
        > HTH
        >
        > Rafat Sarosh[/color]

        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?

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Walking the function stack --- Reflection question.

          Tim Burda <Tim.Burda@si-intl.com> wrote:[color=blue]
          > 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?[/color]

          No, it's not.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          Working...