I have a method where I'm passing in a string:
void MyMethod(string someVar) {...}
The string value is assigned from the configuration file:
ConfigurationManager.AppSettings["MyConfigKey"]
I would like to replace string with something that is typed so I know that parameter is a specific config key value:
void MyMethod(MyConfigKey someVar) {...}
But there are several of these config keys and I'd like to some how group them.
I was thinking of an enum such as:
public enum MyEnum
{
ConfigKey1,
ConfigKey2,
ConfigKey3
}
But then I'd be doing enum conversions all over the place. Some of the config keys are bool, some string, etc.
I could do a static class:
public static class MyClass
{
public static string ConfigKey1 {get,set}
public static bool ConfigKey2 {get,set}
public static string ConfigKey3 {get,set}
}
But then the parameter in MyMethod() is still a string, leaving the door open for any string to drop in.
Any ideas how to have a typed parameter for this scenario so a regular string cannot drop in?