Get dynamic property from Settings

前端 未结 4 964
闹比i
闹比i 2021-01-04 21:01

I\'ve got a few properties stored in my AppConfig and now I want to access them dynamically (e.g. in a loop or function).

Accessing the values using MySettings.NAME_

4条回答
  •  梦谈多话
    2021-01-04 21:55

    String propertyValue = MySettings.GetType()
    .GetProperty("NAME_OF_THAT_THING")
    .GetValue(MySettings, null); //replace MySettings with null in GetValue(...) if MySettings is  a static class
    

提交回复
热议问题