Exploring the stackTrace

  • Thread starter Thread starter Steve B. [Labo.Net]
  • Start date Start date
S

Steve B. [Labo.Net]

Hi

I can step trough the stackTrace using the System.Diagnostic.StackTrace and
System.Diagnostics.StackFrame classes.

But how can I get passed parameters to methods ?

I can get name and type of all parameters using reflection, but not the
actual value.

For example :

public void myMethod(string myString)
{
.... do something ...
GetParams();
}

public void GetParams()
{
... getting values for params ...
foreach( param in ????)
Console.WriteLine(param.Name + Param.Value);
}

GetParams is just an exemple and is succeptible to be called from anywhere

Any idea ?
 
I hoped, as Visual Does to build the watch grid (in debug mode), that there
is a "debug" method to make this possible....

Thanks
Steve


Gabriele G. Ponti said:
Steve,

I don't think there's support in the .NET Framework for peeking at the value
of the parameters via reflection. One possible work-around to this problem
would be do have your GetParams() method accept a variable number of
arguments, and then pass the value of the parameters.

For example:

static private void myMethod(int i, string s)
{
GetParams(new object[] {i, s});
}

static private void GetParams(params object[] args)
{
StackTrace trace = new StackTrace(true);
StackFrame frame = trace.GetFrame(1);

System.Console.WriteLine(frame.GetMethod());
for(int i = 0 ; i < args.Length ; i++)
Console.WriteLine(args);
}

HTH,

Gabriele

Steve B. said:
Hi

I can step trough the stackTrace using the System.Diagnostic.StackTrace and
System.Diagnostics.StackFrame classes.

But how can I get passed parameters to methods ?

I can get name and type of all parameters using reflection, but not the
actual value.

For example :

public void myMethod(string myString)
{
... do something ...
GetParams();
}

public void GetParams()
{
... getting values for params ...
foreach( param in ????)
Console.WriteLine(param.Name + Param.Value);
}

GetParams is just an exemple and is succeptible to be called from anywhere

Any idea ?
 
Back
Top