title: "Store" a type parameter for later use in C#?
body: <p>I'm creating a Settings object in my app, used for storing user-defined settings and whatnot. I plan on using various datatypes for my setting fields (ints, strings, enums, anything Serializable, really).</p>
  
  <p>I'd also like, if possible, a type-safe way to set any of the settings. My proposed method would be doing something like this:</p>
  
  <pre><code>Tuple&lt;string, Type&gt; SettingName = new Tuple&lt;string, Type&gt;("NumberOfFoos",
                                                            typeof(**TYPE**));
  public void Set(Tuple&lt;string, Type&gt; key, **TYPE** value) { /* Stuff */ }
  </code></pre>
  
  <p>The Tuple would effectively be the "setting" that the user would push a value to, and would consist of the key for that setting as well as the type of that setting. What I'm wondering is if there's any way to have the compiler enforce that, in the <code>Set()</code> method, the type of <code>value</code> is of the same type as the type object saved in the tuple passed to <code>Set()</code>? Is the way I proposed even possible? Thanks!</p>
  
  <p>EDIT: I thought of some more things I should clarify.</p>
  
  <p>1) This is intended to be a static class, so I won't be able to serialize the whole class, only members in it. Therefore, I'd really like to not have to deal with a serialization for each field. I was planning on storing all the setting values in a <code>Dictionary&lt;string, **TYPE**&gt;</code> and serializing that.</p>
  
  <p>2) The <code>Tuple</code> definitions are meant to be constant and static. I'm really treating them as more of a typedef-type thing (I really should make my own SettingKey struct), which the user passes to <code>Set</code> to indicate what field they are changing. The Type parameter is meant to enforce the the <code>value</code> parameter is of the specified type.</p>