按字符串获取静态属性

hsz*_*hsz 7 c#

我有public static class MyClass它包含许多public static string参数.

以下我有一些价值

string val = "something";
Run Code Online (Sandbox Code Playgroud)

使用它val我希望能够获得指定的属性 - 比如MyClass.something.我怎样才能做到这一点 ?

Tim*_*son 14

PropertyInfo propertyInfo = typeof(MyClass).GetProperty("something");
string something = (string) propertyInfo.GetValue(null, null);
Run Code Online (Sandbox Code Playgroud)