You can do this, as Conrad suggested using reflection. But I would find it much better to use a dictionary and not rely on reflection for such a task.
public static class Pages
{
private static readonly IDictionary<String, String> PageMap = null;
private static Pages()
{
Pages.PageMap = new Dictionary<String, String>();
Pages.PageMap.Add("LoggedOut", "LoggedOut.aspx");
Pages.PageMap.Add("Login", "Login.aspx");
Pages.PageMap.Add("Home", "Home.aspx");
}
public static GetPage(String pageCode)
{
String page;
if (Pages.PageMap.TryGet(pageCode, out page)
{
return page;
}
else
{
throw new ArgumentException("Page code not found.");
}
}
}
You must, of course, configure error handling to your actual requirements.
source
share