title: Cleanest way to create class from enum type?
body: <p>I have the following enum and classes:</p>
  
  <pre><code>public enum MyEnum
  {
     MyType1,
     MyType2
  }
  
  public abstract class MyBaseClass
  {
     public abstract MyEnum GetMyType();
  }
  
  public class MySubClass : MyBaseClass
  {
     public override MyEnum GetMyType()
     {
        return MyEnum.MyType1;
     }
  }
  </code></pre>
  
  <p>I want to create an instance of MySubClass based on GetMyType(), but without the need to "register" the MySubClass to some kind of handler (or is that the way to go?). I know this is probably easy to do via reflection (loop through Assembly for classes which inherit from MyBaseClass and check their MyType), but is that the way to go?</p>
  
  <p>Right now I'm doing something a long the lines:</p>
  
  <pre><code>public MyBaseClass CreateMyClass(MyEnum myEnum)
  {
     if(myEnum == MyEnum.MyType1)
     {
        return new MySubClass();
     }
     else if(myEnum == MyEnum.MyType2)
     {
        return new MyOtherSubClass();
     }
  }
  </code></pre>
  
  <p>Which eventually will result in me forgetting to manually add new classes. It will be caught in a Test, but I'd rather not having to add classes at all since all the information needed is already provided.</p>
  
  <p>Open to all kind of suggestions regarding the best approach.</p>