How can I use Reflection to get readonly static property? The access modifier (open, protected, closed) does not matter.
you can use the GetProperty () method of the Type class: http://msdn.microsoft.com/en-us/library/kz0a8sxy.aspx
Type t = typeof(MyType); PropertyInfo pi = t.GetProperty("Foo"); object value = pi.GetValue(null, null); class MyType { public static string Foo { get { return "bar"; } } }
Use Type.GetProperty () with BindingFlags.Static. Then PropertyInfo.GetValue ().
Just like you get any other property (for example, see the answer to this question ).
The only difference is that you would indicate nullas the target when invoked GetValue.
null
GetValue