trace of function call

hi,
how can i trace source (class or namespace) of function call inside of code?
[86 byte] By [gibic] at [2007-12-16]
# 1
You can use the System.Diagnostics.StackTrace class.

-Ryan / Kardax

RyanLamansky at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

This is an interesting question.

Henrysoftware at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
Here's a code snippet


System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();
System.Diagnostics.Debug.Assert(trace.FrameCount > 0);
Console.WriteLine(trace.GetFrame(0).GetMethod().Name);


This will give you the Method name in which the code is currently executing.


trace.GetFrame(0).GetMethod().DeclaringType.Namespace

will give you namespace


trace.GetFrame(0).GetMethod().DeclaringType.Name

will give you the class/struct name

Using StackTrace you can get all frames upto the bottom of the stack.

VijayeRaji at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...