开发者

dumping static properties in linqpad

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.

If I have alot of auto generated static properties how do I dump ever开发者_如何学Cything?


Reflection works

typeof(Test)
.GetFields(BindingFlags.Static | BindingFlags.Public)
.Select(f => new { name = f.Name, value = f.GetValue(null)})
.Dump();

dumping static properties in linqpad


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜