public class Test
{
public int a = 2;
public static int b = 5;
public struct C
{
public int d = 9;
public static int e = 7;
}
}
new Test().Dump();
The code above will dump the newly created object and list a
as a property but won't list b
or the nested static struct C
or anything inside of it.
Reflection works
typeof(Test)
.GetFields(BindingFlags.Static | BindingFlags.Public)
.Select(f => new { name = f.Name, value = f.GetValue(null)})
.Dump();
The static instance variables are not part of the "new Test()" instance that you are creating. They are part of the static instance of of the Test class. You can read up on static classes and Static class members here.
You can see the static variables by using
(Test.b).Dump();
(Test.C.e).Dump();
Hope this helps.
精彩评论