If key is either assembly-qualified, or namespace-qualified within either the core assemblies or the calling assembly, then:
Type type = Type.GetType(key);
return constructorParameter == null ? Activator.CreateInstance(type)
: Activator.CreateInstance(type, constructorParameter);
I wonder, though, if:
public static object getClassInstance(string key, params object[] args)
is more flexible, allowing:
Type type = Type.GetType(key);
return Activator.CreateInstance(type, args);
with usage such as:
object o = getClassInstance(key); // uses default constructor
object o = getClassInstance(key, null); // passes null to single parameter
object o = getClassInstance(key, 123, "abc"); // etc