Created
July 15, 2015 20:07
-
-
Save angelovstanton/301debdc0827ce507030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string appConfigFilePath = string.Concat(Assembly.GetExecutingAssembly().Location, ".config"); | |
ConfigModificatorSettings appConfigWriterSettings = | |
new ConfigModificatorSettings("//appSettings", "//add[@key='{0}']", appConfigFilePath); | |
string value = ConfigurationManager.AppSettings["testKey1"]; | |
System.Console.WriteLine("Value before modification: {0}", value); | |
ConfigModificator.ChangeValueByKey( | |
key: "testKey1", | |
value: "ChangedValueByModificator", | |
attributeForChange: "value", | |
configWriterSettings: appConfigWriterSettings); | |
ConfigModificator.RefreshAppSettings(); | |
value = ConfigurationManager.AppSettings["testKey1"]; | |
System.Console.WriteLine("Value after modification: {0}", value); | |
//Example how to change Custom XML configuration | |
string carsConfigFilePath = "Cars.xml"; | |
ConfigModificatorSettings carsConfigWriterSettings = | |
new ConfigModificatorSettings("//cars", "//car[@name='{0}']", carsConfigFilePath); | |
ConfigModificator.ChangeValueByKey( | |
key: "BMW", | |
value: "Mazda", | |
attributeForChange: "name", | |
configWriterSettings: carsConfigWriterSettings); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment