June 2003
Intermediate to advanced
800 pages
34h 20m
English
You want to create an instance of an object that’s named in a string.
Use the Assembly.CreateInstance method or the Activator.CreateInstance method.
Both the System.Reflection.Assembly and the System.Activator classes provide a CreateInstance method. This recipe uses the Assembly class, and recipe Invoke a Method by Name features an example with the Activator class.
To use CreateInstance, you supply a fully qualified type name. The CreateInstance method searches the assembly for the corresponding type, and then it creates and returns a new instance of the object (or a null reference if the object can’t be found). You can also use overloaded versions of CreateInstance to supply constructor arguments ...
Read now
Unlock full access