I have an enum which I want to get from the web.config at run-time. I started reading about build providers, but this seems to work for classes. Can someone point me to an example, or at least point me in the right direction.
Right now I have a comma separated list of values in the web.config, and this is not type-safe and is prone to errors.
If there is another approach to get this type of "dynamic-enum", I'm open to other ideas.
Thank you!
You can use ConfigurationManager and convert value to enum:
<configuration> <appSettings> <add key="YourEnum" value="BlueSky" /> </appSettings> </configuration>
string configValue = ConfigurationManager.AppSettings["YourEnum"]; YourEnumType value = (YourEnumType)Enum.Parse(typeof(YourEnumType), configValue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With