Hi,
I'm not sure how to get the VALUE of the parameters being passed into the
method. You can get there name, position and type via ParameterInfo, but
I'm at a loss on how to get the value.
Also see the examples:
http://msdn2.microsoft.com/en-us/library/system.diagnostics.stackframe(vs.80).aspx
and
http://msdn2.microsoft.com/en-us/library/system.diagnostics.stacktrace(VS.80).aspx
Here's an example of getting the names of the parameters:
using System;
using System.Diagnostics;
using System.Reflection;
namespace SamplePublic
{
// This console application illustrates various uses
// of the StackTrace and StackFrame classes.
class ConsoleApp
{
[STAThread]
static void Main()
{
Method1();
Console.WriteLine("Hit enter to exit.");
Console.ReadLine();
}
private static void Method1()
{
Method2();
}
private static void Method2()
{
Method3();
}
private static void Method3()
{
Method4("Hello", "World");
}
private static void Method4(string data1, string data2)
{
Method5();
}
private static void Method5()
{
StackTrace st = new StackTrace(true);
// Console.WriteLine(" Stack trace for this level: {0}",
st.ToString());
for (int i = 0; i < st.FrameCount; i++)
{
StackFrame sf = st.GetFrame(i);
Console.WriteLine(" File: {0}", sf.GetFileName());
Console.WriteLine(" Line Number: {0}", sf.GetFileLineNumber());
Console.WriteLine(" Column Number: {0}",
sf.GetFileColumnNumber());
MethodBase mb = sf.GetMethod();
Console.WriteLine("--Method called: " + mb.Name);
foreach (ParameterInfo pi in mb.GetParameters())
{
Console.WriteLine("----Parameter Name: " + pi.Name);
Console.WriteLine("----Parameter Type: " + pi.ParameterType);
Console.WriteLine("----Parameter Position: " + pi.Position);
}
}
}
}
}
Dave