How to instantiate an object using a string in C#

P

Prashant

Hi ,

Need some help ! .
I am storing Classnames in an XML file and depending on
the user's choice of process want to :

1) Read the classname of that process from the XML file
2) Instantiate an object of that class from the string
received from the XML (which is the classname)

No problem reading the XML and getting the Classname as
string , but how to use that string and instantiate an
object of that class using C# .

Any help would be highly appreciated.

thanks
Prashant
 
J

Jeff Langston

try this:

(cast to your favorite
object)System.Reflection.Activator.CreateInstance("assembly name","type
name");
 
P

Prashant

Thanks everybody ,

It worked using Reflection . I did it by getting the
Executing Assembly and calling the CreateInstance method
for it . (passing the class name as string ).

Thanks
Prashant
 

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

Top