title: Type safe enum pattern implementation with generics
body: <p>How could the typesafe enum pattern be implemented on a generic class? Let's assume it's implemented along these lines</p>
  
  <pre><code>public class KnownSetting&lt;T&gt;
  {
      public readonly static KnownSetting&lt;String&gt; Name = new KnownSetting&lt;String&gt;("name", "Default Name", t =&gt; t);
      public readonly static KnownSetting&lt;int&gt; Size = new KnownSetting&lt;String&gt;("size", "25", t =&gt; Converter.ToInt32);
  
      public String Key { get; set; }
      public T DefaultValue { get; set; }
      public Func&lt;String, T&gt; Converter { get; set; }
  
      private KnownSetting(String key, T defaultValue, Func&lt;String, T&gt; converter)
      {
          Key = key;
          DefaultValue = defaultValue;
          Converter = converter;
      }
  }
  </code></pre>
  
  <p>The implementation of the pattern is correct this way since the constructor remains private, but when using this construct, it looks wrong:</p>
  
  <pre><code>public static class Program
  {
      public static void main()
      {
          var x = KnownSetting&lt;?&gt;.Name;
      }
  }
  </code></pre>
  
  <p>Then an option would be to split it in two, KnownSetting container class and the Setting implementation, but then the scope of the constructor cannot be private so as to be instantiated from within the container.</p>
  
  <p>How can this pattern be implemented so that the generics aspect of it stays concealed from the end-user, but remains strongly typed? Is there a more suitable pattern, or is there a better way to implement it?</p>
  
  <p><strong>Update</strong>
  I added a second sample to illustrate that I do want the type of the setting to be generic.</p>