472,139 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

how to: instantiate object if only its name (e.g. "foo") is known

TR
At runtime, I'd like to instantiate an object (e.g. myInvoice) when all I
know is the name of the class that has to instantiated (e.g. "Invoice").

Dim DesiredClass as String = "Invoice"
'// now create an instance of the desired class
???

Can this be done?

I hope the question is clear.
Thanks
TR
Nov 21 '05 #1
3 1041
"TR" <tr@anonymous.biz> schrieb:
At runtime, I'd like to instantiate an object (e.g. myInvoice) when all I
know is the name of the class that has to instantiated (e.g. "Invoice").


You can use 'Activator.CreateInstance' to do that. Samples can be found
here (ignore the German text and take a look at the listings):

<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#ClassByName>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
TR
Vielen Dank!
TR

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
"TR" <tr@anonymous.biz> schrieb:
At runtime, I'd like to instantiate an object (e.g. myInvoice) when all I know is the name of the class that has to instantiated (e.g. "Invoice").


You can use 'Activator.CreateInstance' to do that. Samples can be found
here (ignore the German text and take a look at the listings):

<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#ClassByName>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"TR" <tr@anonymous.biz> schrieb:
Vielen Dank!


:-)

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Oleg Alistratov | last post: by
3 posts views Thread by George Varelas | last post: by
3 posts views Thread by =?Utf-8?B?Umljaw==?= | last post: by
12 posts views Thread by Shannon Mayne | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.