.NET allows you to use .settings files to manage application settings. I would like to store Production, Development and Test settings separately in a way that I can do something like this:
EnvironmentSettings environmentSettings;
// get the current environment (Production, Development or Test)
ApplicationEnvironment Environment = (ApplicationEnvironment)
Enum.Parse(typeof(ApplicationEnvironment), Settings.Default.ApplicationEnvironment);
switch (Environment)
{
case ApplicationEnvironment.Production:
environmentSettings = Settings.Production;
break;
...
}
string reportOutputLocation = environmentSettings.ReportOutputLocation;
Basically, I want two separate Settings classes: the general Settings class that stores the selected environment and non-environment specific properties, and 3 static instances of a second class called EnvironmentSettings. The instance used should depend on the environment specified in the general Settings class.
Is there any way to do this short of manually setting the values for all these settings in a static constructor or something? If I have to do that, I'd rather just have one big Settings class with properties like "DevOutputLocation", "LiveOutputLocation", etc.
I can have multiple .settings files in my project but that just creates separate classes that don't derive from each other. So I could make DevelopmentSettings.settings, ProductionSettings.settings and TestSettings.settings files and give them the same properties, but then I would need a bunch of switch statements everywhere to determine which class to use because they don't derive from a common class.