Can I get the method local variables through a stack trace in C#?
Posted
by smwikipedia
on Stack Overflow
See other posts from Stack Overflow
or by smwikipedia
Published on 2010-04-23T06:38:32Z
Indexed on
2010/04/23
6:43 UTC
Read the original article
Hit count: 290
I want to get a detailed log about my stack trace. I can get a StackFrame and then the method and then get all the parameters of that method. Just as the following code:
StackTrace st = new StackTrace();
StackFrame[] sfs = st.GetFrames();
foreach (StackFrame sf in sfs)
{
MethodBase method = sf.GetMethod();
ParameterInfo[] pis = method.GetParameters();
foreach (ParameterInfo pi in pis)
{
....
}
Console.WriteLine(method.Name);
}
But how could I get the local variables infomation within a method?
Could someone shed some light on me?
Many thanks.
© Stack Overflow or respective owner