title: Testing the typesafe enum pattern in C#
body: <p>I am utilizing the "typesafe enum pattern"</p>
  
  <pre><code>public class Level
  {
      public static readonly Level Low = new Level(0, "Low");
      public static readonly Level Medium = new Level(1, "Medium");
      public static readonly Level High = new Level(2, "High");
  
      private int _value;
      private string name;
  
      private Level(int value, string name)
      {
          _value=value;
          _name=name;
      }
  }
  </code></pre>
  
  <p>For testing purposes I need to create an invalid Level which I do with reflection.</p>
  
  <pre><code>int id = -1;
  string value = "invalid";
  var constructor = typeof(Level).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] {typeof(int), typeof(string)}, null);
  var invalidLevel = (Level)constructor.Invoke(new object[] {id, value});
  </code></pre>
  
  <p>Using reflection to access the private constructor seems.... wrong to me. Is there a better way to make an invalid Level?</p>