How to get a Static property with Reflection

后端 未结 8 1297
旧巷少年郎
旧巷少年郎 2020-11-28 05:44

So this seems pretty basic but I can\'t get it to work. I have an Object, and I am using reflection to get to it\'s public properties. One of these properties is static an

8条回答
  •  时光取名叫无心
    2020-11-28 06:30

    Or just look at this...

    Type type = typeof(MyClass); // MyClass is static class with static properties
    foreach (var p in type.GetProperties())
    {
       var v = p.GetValue(null, null); // static classes cannot be instanced, so use null...
    }
    

提交回复
热议问题