Is it possible to dynamically create static fields in a class?
class Pages
{
private static T getPages<T>() where T : new()
{
var page = new T();
PageFactory.InitElements(Browsers.getDriver, page);
return page;
}
public static HomePage Home => getPages<HomePage>();
public static DashboardPage Dashboard => getPages<DashboardPage>();
public static ProfilePage Profile => getPages<ProfilePage>();
}
Right now I'm adding them one by one myself. Is there a way to dynamically add them? HomePage
, DashboardPage
and ProfilePage
live under MyProject.Pages namespace, if I know how to dynamically create the static fields, I could loop through that namespace and dynamically create them.