Function name

  • Thread starter Thread starter Vadym Stetsyak
  • Start date Start date
V

Vadym Stetsyak

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
 
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.

"System.Diagnostics" 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.WriteLine(frame.GetFileName());
Console.WriteLine(frame.GetFileLineNumber());
Console.WriteLine(frame.GetFileColumnNumber());
Console.WriteLine(frame.GetMethod());
}
}

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


</code>

...
Regards,
Vadim.
 
thank you, Vadim.

Vadim Melnik said:
Hello,


"System.Diagnostics" 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.WriteLine(frame.GetFileName());
Console.WriteLine(frame.GetFileLineNumber());
Console.WriteLine(frame.GetFileColumnNumber());
Console.WriteLine(frame.GetMethod());
}
}

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


</code>

..
Regards,
Vadim.
 
Back
Top