I have an abstract class Step, and many descendant Step classes that I would like to instantiate based on an XML document.
As such I would like to create an instance of a particular step class based on the type in the XML document
Step type="GenerateReport" .... Step type="PrintReport" ....
How can I instantiate an object by specifying the classname (and ideally the parameters to be passed through to the constructor)?
I think you simply want to use the Activator.CreateInstance
method:
var object = Activator.CreateInstance(null, "Classname");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With