Function name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vadym Stetsyak

    #1

    Function name

    Hello!

    How can I get the info about the function at which goes the execution.

    I mean information that can be obtained with the help of
    __FUNCTION__ , __FILE__, __LINE__ in the C-language.

    --
    Vadym Stetsyak
    ICQ 161730125

    He, who commands the past - commands the future
    He, who commands the present - commands the past


  • Vadim Melnik

    #2
    Re: Function name

    Hello,
    [color=blue]
    > How can I get the info about the function at which goes the execution.
    >
    > I mean information that can be obtained with the help of
    > __FUNCTION__ , __FILE__, __LINE__ in the C-language.[/color]

    "System.Diagnos tics" namespace contains interesting helper classes -
    StackTrace and StackFrame. Below listed code sample demonstrating how it
    works. Unfortunately it's not exactly what you need, this code only works
    for Debug build, and IIRC it requires in debug symbols (.pdb file), where
    stored information about files, line numbers, etc.

    <code>
    public class Foo
    {
    public void foo1()
    {
    foo2();
    }

    public void foo2()
    {
    foo3();
    }

    public void foo3()
    {
    StackTrace st = new StackTrace(0, true);
    StackFrame frame = st.GetFrame(0);
    Console.WriteLi ne(frame.GetFil eName());
    Console.WriteLi ne(frame.GetFil eLineNumber());
    Console.WriteLi ne(frame.GetFil eColumnNumber() );
    Console.WriteLi ne(frame.GetMet hod());
    }
    }

    .....
    Foo foo = new Foo();
    foo.foo1();


    </code>

    ...
    Regards,
    Vadim.


    Comment

    • Vadym Stetsyak

      #3
      Re: Function name

      thank you, Vadim.

      "Vadim Melnik" <vmnews@REMOVET HISdocsultant.c om> wrote in message
      news:uMEoFFwSDH A.3796@tk2msftn gp13.phx.gbl...[color=blue]
      > Hello,
      >[color=green]
      > > How can I get the info about the function at which goes the execution.
      > >
      > > I mean information that can be obtained with the help of
      > > __FUNCTION__ , __FILE__, __LINE__ in the C-language.[/color]
      >
      > "System.Diagnos tics" namespace contains interesting helper classes -
      > StackTrace and StackFrame. Below listed code sample demonstrating how it
      > works. Unfortunately it's not exactly what you need, this code only works
      > for Debug build, and IIRC it requires in debug symbols (.pdb file), where
      > stored information about files, line numbers, etc.
      >
      > <code>
      > public class Foo
      > {
      > public void foo1()
      > {
      > foo2();
      > }
      >
      > public void foo2()
      > {
      > foo3();
      > }
      >
      > public void foo3()
      > {
      > StackTrace st = new StackTrace(0, true);
      > StackFrame frame = st.GetFrame(0);
      > Console.WriteLi ne(frame.GetFil eName());
      > Console.WriteLi ne(frame.GetFil eLineNumber());
      > Console.WriteLi ne(frame.GetFil eColumnNumber() );
      > Console.WriteLi ne(frame.GetMet hod());
      > }
      > }
      >
      > ....
      > Foo foo = new Foo();
      > foo.foo1();
      >
      >
      > </code>
      >
      > ..
      > Regards,
      > Vadim.
      >
      >[/color]


      Comment

      Working...