Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get static property by string

Tags:

c#

I have public static class MyClass which contains many public static string parameters.

Following I have some value

string val = "something";

Using that val I want to be able to get specified property - like MyClass.something. How can I do that ?

like image 233
hsz Avatar asked Dec 12 '10 14:12

hsz


1 Answers

PropertyInfo propertyInfo = typeof(MyClass).GetProperty("something");
string something = (string) propertyInfo.GetValue(null, null);
like image 85
Tim Robinson Avatar answered Nov 20 '22 03:11

Tim Robinson