// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Specialized; using System.Configuration; using System.Configuration.Internal; using System.Reflection; namespace E { public class MyConfig : IInternalConfigSystem { public NameValueCollection appset; public MyConfig() { appset = new NameValueCollection(); appset.Add("somekey", "someothervalue"); // this could come from another file or from a database or from wherever } public object GetSection(string key) { if(key == "appSettings") { return appset; } else { return null; } } public void RefreshConfig(string sectionName) { } public bool SupportsUserConfig { get; private set; } } public class Program { public static void Main(string[] args) { Console.WriteLine(ConfigurationManager.AppSettings["somekey"]); Type type = typeof(ConfigurationManager); FieldInfo info = type.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static); info.SetValue(null, new MyConfig()); Console.WriteLine(ConfigurationManager.AppSettings["somekey"]); } } }