This for C#? Passing Class type as a parameter
I have a class adapter that implements an Interface. I want to fill an array structure with MyFooClass instances where M
You probably want to use Activator.CreateInstance.
IElemRequest req = (IElemRequest) Activator.CreateInstance(Baz);
If the type that Baz
represents has a constructor that takes parameters, the complexity of that will grow (as you'll have to use Reflection or dynamic calls to make it work). If Baz
doesn't represent a type that inherits from IElemRequest
, you will get an ugly runtime error.