How to pass an enum to a parent class's static function to instantiate a child class?
<p>I have a 3 classes, <code>ParentClass</code>,<code>ClassA</code>,<code>ClassB</code>. Both <code>ClassA</code> and <code>ClassB</code> are subclasses of <code>ParentClass</code>. I wanna try to create objects of type <code>ClassA</code> or <code>ClassB</code> using some kind of enumeration to identify a type, and then instantiate the object cast as the parent type. How can I do that dynamically? Please take a look at the code below, and the parts that say <code>//what do I put here?</code>. Thanks for reading!</p>

<pre><code>enum ClassType
{
    ClassA,
    ClassB
};
public abstract class ParentClass
{


    public ParentClass()
    {
        //....
    }

    public static ParentClass GetNewObjectOfType(ClassType type)
    {
        switch(type)
        {
            case ClassType.ClassA: 
                //What do I put here?
                break;
            case ClassType.ClassB:
                //What do I put here?
                break;
        }

        return null;
    }
}

public class ClassA:ParentClass
{
    //....
}
public class ClassB:ParentClass
{
    //.......
}
</code></pre>
