Ben Voigt [C++ MVP] <rb*@nospam.nospamwrote:
No - in particular, local variables and parameters won't *have* names
when debug information hasn't been built.
You can get the types of local variables for any method though. See the
example in the LocalVariableInfo class.
Ah, haven't looked at that. I wonder if it gives entries for local
variables which are introduced by the compiler but don't represent
actual local variables in the original source code. Must play some
time.
To get the current method you can
use the StackTrace class (is there a more efficient way to get just the top
method?)
using System;
using System.Reflection;
public class ConvertFile
{
public static void Main(string[] args)
{
MethodBase b = MethodBase.GetCurrentMethod();
Console.WriteLine (b.Name);
MethodBody body = b.GetMethodBody();
foreach (LocalVariableInfo info in body.LocalVariables)
{
Console.WriteLine (info.LocalType);
}
}
}
Intriguing...
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too