Get value of static field

.net, c#, reflection, static-members

Solution

You can use the following:

var field = typeof(Pages).GetField("Home", BindingFlags.Public | BindingFlags.Static);
var value = (string)field.GetValue(null);

Problem

I've got the following class: ``` public static class Pages { public static string LoggedOut = "LoggedOut.aspx"; public static string Login = "Login.aspx"; public static string Home = "Home.aspx"; } ``` I know I can use `Pages.Home` statically, but there is a reason for my question. I wish to have a method that I can call like this: ``` string pageName = Pages.GetPage("Home"); ``` etc. C'est possible? Thanks, Dave

Original source