C# Programming
07-10-2009, 03:50 PM
I am using Relection to get Methods from an Assembly.
I want to display the local Variable names in a method.
I have a test method called Test.
public void Test()
{
string myString = string.Empty;
int myInt = 0;
}
So I am using the following code:
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
List methods= new List(methodInfo);
foreach (MethodInfo method in methods)
{
MethodBody methodBody = method.GetMethodBody();
IList localVariables = methodBody.LocalVariables;
}
My problem is, even if I loop through the localVariables collection, I am not able to get the name of the variables of Test Method.
Kindly let me know how do I get the variable names.
Thanks in Advance.
I want to display the local Variable names in a method.
I have a test method called Test.
public void Test()
{
string myString = string.Empty;
int myInt = 0;
}
So I am using the following code:
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
List methods= new List(methodInfo);
foreach (MethodInfo method in methods)
{
MethodBody methodBody = method.GetMethodBody();
IList localVariables = methodBody.LocalVariables;
}
My problem is, even if I loop through the localVariables collection, I am not able to get the name of the variables of Test Method.
Kindly let me know how do I get the variable names.
Thanks in Advance.