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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top