
Creating objects at runtime
Hello
I am answering my own question, this could be achieved using the following:
Dim hdlSample As ObjectHandle
Dim myExtenderInterface As Equities
hdlSample = Activator.CreateInstance("SampleAssembly",
"samplenamespace.Bonds", True)
myExtenderInterface = CType(hdlSample.Unwrap(), IMyExtenderInterface)
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"))
Is there a better way.
TIA
Yaz
Quote:
> Hello
> I have an abstract class called Equities and two other classes called
Bonds
> and Mutuals that derive from Equities.
> I first declare the object of type Equities and when they click on an
option
> button I return an object of type Bonds or Mutuals. I kown this can be
> achieved using a select case and return an object of type Bonds or
Mutuals.
> If I had ten different types of objects, I think this very ugly select
case.
> Is there another way of achieving this without the select case, in other
> words given an ID I get a string and then invoke it to create the object
> with the proper type.
> TIA
> Yaz