How to create and object by type name

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

Suppose I have a
string s="System.Windows.Forms.Label";

and I would like to create a corresponding object.

object o = ObjectByTypeName(s);

How do I implement ObjectByTypeName function, having in mind that s may be
just any valid object type name? For simplicity we may suppose that the
specified type has a default constructor (constructor with no parameters).
 
See documentation for System.Activator class, it has CreateInstance and
CreateInstanceFrom etc methods for creating object instances dynamically.
 
Back
Top