J
John Bailo
Is it possible to Reflect a variable inside a method?
I can Reflect a class field using GetField, but can I reflect a
variable/field from inside member?
For example, I want to Reflect samp inside of the method:
public int myMethod()
{
string samp = "five";
// Get type information for the method.
// This produces a result:
MethodInfo mInfo = this.GetType().GetMethod("myMethod");
//I though this would give me access to samp
//but it returns null:
FieldInfo fi = this.GetType().GetField("samp");
string varValue = (string) fi.GetValue( this );
Debug.WriteLine(varValue); // no value written
}
I can Reflect a class field using GetField, but can I reflect a
variable/field from inside member?
For example, I want to Reflect samp inside of the method:
public int myMethod()
{
string samp = "five";
// Get type information for the method.
// This produces a result:
MethodInfo mInfo = this.GetType().GetMethod("myMethod");
//I though this would give me access to samp
//but it returns null:
FieldInfo fi = this.GetType().GetField("samp");
string varValue = (string) fi.GetValue( this );
Debug.WriteLine(varValue); // no value written
}