Cast to a type from the type name as a string

Viewed 23245

I have an existing base type and I would like to cast it to a derived type base upon the name of the type as a string, so something like this:

public void DoStuffInDerivedType(string derivedName) {
   (base as Type.GetType(derivedName)).DoThisThing();
}

I'm pretty sure this can't be done but would be good to know for sure. Thanks

EDIT: I understand that I could construct the object using reflection from the type name but I want use an existing object. And also I know this is generally a bad idea. However I wanted to use this for a SpecFlow BDD Feature.

2 Answers
Related