title: Need to create a dynamic ConfigurationSection that also holds the type
body: <p>I need to create a configuration section, that is able to store key-value pairs in an app.config file and the key-value pairs can be added runtime regardless of their type. It is also important that the value keeps its original type. I need to extend the following interface </p>
  
  <pre><code>public interface IPreferencesBackend
  {
      bool TryGet&lt;T&gt;(string key, out T value);
      bool TrySet&lt;T&gt;(string key, T value); 
  }
  </code></pre>
  
  <p>At runtime, I can say something like: </p>
  
  <pre><code>My.Foo.Data data = new My.Foo.Data("blabla");
  Pref pref = new Preferences();
  pref.TrySet("foo.data", data); 
  pref.Save();
  
  My.Foo.Data date = new My.Foo.Data();
  pref.TryGet("foo.data", out data);
  </code></pre>
  
  <p>I tried with System.Configuration.Configuration.AppSettings, but the problem with that that it is storing the key-value pairs in a string array. </p>
  
  <p>What I need is to have an implementation of System.Configuration.ConfigurationSection, where I can control the how the individual setting is serialized. I noticed that the settings generated by Visual Studio kind of do this. It is using reflection to create all the setting keys. what I need is to do this runtime and dynamically. </p>
  
  <pre><code>[System.Configuration.UserScopedSettingAttribute()]
  [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  [System.Configuration.DefaultSettingValueAttribute("2008-09-24")]
  public global::System.DateTime DateTime {
     get {
          return ((global::System.DateTime)(this["DateTime"]));
         }
     set {
          this["DateTime"] = value;
         }
   }
  </code></pre>