Wednesday, March 13, 2013

Using StackFrame Class to get the stack information

using System.Diagnostics;
...

//Gets the file name that contains the code that is executing. This information is typically extracted from the debugging symbols for the executable.
public static int GetFileLineNumber()
{
    StackFrame s = new StackFrame(1, true);
    return s.GetFileLineNumber();
}


//Gets the method in which the frame is executing.
public static string GetMethod()
{
    StackFrame s = new StackFrame(1, true);
    return s.GetMethod().Name;
}


//Gets the file name that contains the code that is executing. This information is typically extracted from the debugging symbols for the executable.
public static string GetFileName()
{
    StackFrame s = new StackFrame(1, true);
    return s.GetFileName();
}


Read: http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.aspx

No comments:

Post a Comment