title: Parse to Nullable Enum
body: <p>I am trying to parse a string back to a nullable property of type MyEnum.</p>
  
  <pre><code>public MyEnum? MyEnumProperty { get; set; }
  </code></pre>
  
  <p>I am getting an error on line:</p>
  
  <pre><code>Enum result = Enum.Parse(t, "One") as Enum;
  // Type provided must be an Enum. Parameter name: enumType
  </code></pre>
  
  <p>I have a sample console test below. The code works if I remove nullable on the property <code>MyEntity.MyEnumProperty</code>.</p>
  
  <p>How can I get the code to work without knowing the typeOf enum except via reflection?</p>
  
  <pre><code>static void Main(string[] args)
      {
          MyEntity e = new MyEntity();
          Type type = e.GetType();
          PropertyInfo myEnumPropertyInfo = type.GetProperty("MyEnumProperty");
  
          Type t = myEnumPropertyInfo.PropertyType;
          Enum result = Enum.Parse(t, "One") as Enum;
  
          Console.WriteLine("result != null : {0}", result != null);
          Console.ReadKey();
      }
  
      public class MyEntity
      {
          public MyEnum? MyEnumProperty { get; set; }
      }
  
      public enum MyEnum
      {
          One,
          Two
      }
  }
  </code></pre>