By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

Function name

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Nov 13 '05 #2

P: n/a
thank you, Vadim.

"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:uM**************@tk2msftngp13.phx.gbl...
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.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.