c# - Different app.config appSettings based on app.config value -


i have app.config

<?xml version="1.0" encoding="utf-8"?> <configuration>     <appsettings>                <!--one set of properties-->         <add key="condition" value="a"/>         <add key="dependingpropertya" value="b"/>         <add key="dependingpropertyb" value="c"/>         <!--another set of properties-->         <add key="condition" value="b"/>         <add key="dependingpropertya" value="d"/>         <add key="dependingpropertyb" value="e"/>     </appsettings> </configuration> 

so want if condition == define 1 set of properties , if condition == b - different set of properties when switch between , b don't need change other properties. possible?

if property names same each "condition" (environment perhaps?), can little coding wizardry:

(app.config:)

<?xml version="1.0" encoding="utf-8"?> <configuration>   <appsettings>             <!--condition 'selector', change value 'condb' when want switch-->     <add key="condition" value="conda"/>      <add key="conda.dependingpropertya" value="b"/>     <add key="conda.dependingpropertyb" value="c"/>     <add key="condb.dependingpropertya" value="d"/>     <add key="condb.dependingpropertyb" value="e"/>   </appsettings> </configuration> 

then, let's say, in c# .net code:

string keyprepend = system.configuration.configurationmanager.appsettings["condition"];  string propavalue = system.configuration.configurationmanager.appsettings[string.format("{0}.{1}", keyprepend, "dependingpropertya")]; string propbvalue = system.configuration.configurationmanager.appsettings[string.format("{0}.{1}", keyprepend, "dependingpropertyb")]; 

this let's switch set of key/values want use based on single condition key's value.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -