Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can try to use <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx" rel="noreferrer">Configuration</a> and Add <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationsection.aspx" rel="noreferrer">ConfigurationSection</a> on runtime</p> <pre><code>Configuration applicationConfiguration = ConfigurationManager.OpenMappedExeConfiguration( new ExeConfigurationFileMap(){ExeConfigFilename = path_to_your_config, ConfigurationUserLevel.None ); applicationConfiguration.Sections.Add("section",new YourSection()) applicationConfiguration.Save(ConfigurationSaveMode.Full,true); </code></pre> <p><strong>EDIT:</strong> Here is solution based on reflection (not very nice though)</p> <p>Create class derived from <code>IInternalConfigSystem</code></p> <pre><code>public class ConfigeSystem: IInternalConfigSystem { public NameValueCollection Settings = new NameValueCollection(); #region Implementation of IInternalConfigSystem public object GetSection(string configKey) { return Settings; } public void RefreshConfig(string sectionName) { //throw new NotImplementedException(); } public bool SupportsUserConfig { get; private set; } #endregion } </code></pre> <p>then via reflection set it to private field in <code>ConfigurationManager</code></p> <pre><code> ConfigeSystem configSystem = new ConfigeSystem(); configSystem.Settings.Add("s1","S"); Type type = typeof(ConfigurationManager); FieldInfo info = type.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static); info.SetValue(null, configSystem); bool res = ConfigurationManager.AppSettings["s1"] == "S"; // return true </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload