Function name

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
 
V

Vadim Melnik

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

Vadym Stetsyak

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top