C#: Instantiating a class of Unknown Type
The project I am currently working on has several dozen different types of Form classes, each of which is accessible from a common menu strip. Rather than repeatedly instantiating each of the forms from the menu item handlers, I wanted to funnel the request to a single function.
The problem is: How do you instantiate a form when the type is unknown?
The code snippet is:
CreateForm( typeof(CustomFormType) );
Form CreateForm( Type formType )
{
return (Form)Activator.CreateInstance(formType);
}