Hi Egbert,
As Armin has said, you can use the System.Activato r.CreateInstanc e methods
to create an instance, but be aware that this pseudo-code:
Dim MyClassName as String = "MyClass"
Dim MyObject as New MyClasses(MyCla ssName)
is not very robust. If the name of the type "MyClass" changes and you don´t
update that string, your code will fail at run-time. A more common approach
is to create the instance from the type:
System.Activato r.CreateInstanc e(type), and you can get the type through
several ways. For example, you can get the types of an assembly with
Assembly.GetTyp es, or only the public types with Assembly.GetExp ortedTypes.
You can examine some properties (the bases or implemented interfaces) of the
type to guess which ones you want to create instances from. This is quite
common when creating plug-in frameworks.
Bottom line: if you know what you are doing, OK, but if not you can think
about the above.
--
Best regards,
Carlos J. Quintero
MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Bert" <ed*******@aequ or.nl> escribió en el mensaje
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,
I want to create an instance of a class by means of the classname. Can't
figure out how.
in pseudocode this would look like:
Dim MyClassName as String = "MyClass"
Dim MyObject as New MyClasses(MyCla ssName)
Thanks for your help,
Egbert