GetValue on static field inside nested classes.
- by Sir Gallahad
Hi...
I have the following class declared. I need to retreive the class structure and the static values without instanciate it.
public MyClass()
{
public static string field = "Value";
public nestedClass()
{
public static string nestedField = "NestedValue";
}
}
I've successfuly used GetFields and GetNestedType to recover the class structure and GetValue(null) works fine on field, but not on nestedField.
Let me sample:
var fi = typeof(MyClass).GetField("field", BindingFlags.Public | BindingFlags.Static);
var nt = typeof(MyClass).GetNestedType("nestedClass", BindingFlags.Public);
var nfi = nt.GetField("nestedField", BindingFlags.Public | BindingFlags.Static);
// All the above references are detected correctly
var value = fi.GetValue(null); // until here everything works fine. value == "Value"
var nestedValue = nfi.GetValue(null); // this one does not work!!
Anyone knows why the last line does not work and how to work around?
Thanks.