Hi
I have an interface for a "factory" defined like this:
public interface IDeviceFactory<T: IDisposable
{
T GetDevice();
}
Then I can define various factories like:
public class DefaultDeviceFactory<T: IDeviceFactory<T>
{
...
}
public class AVDeviceFactory<T: IDeviceFactory<T>
{
...
}
And from a program I can instantiate these "device factories" in the
following fashion:
IDeviceFactory<ITelevisiontvDeviceFactory = new AVDeviceFactory
<ITelevsion>();
and call
ITelevision tv = tvDeviceFactory.GetDevice();
(The AVDeviceFactory<Tobject knows how to instantiate the appropriate
"devices").
But how can I write a "generic" factory instantiation function? I know
the interface "IDeviceFactory" at compile time, but the particular type T
I only know at runtime. Is this possible?
I mean, how do I write a method like the following, where I know the
"factory type" (eg AVDeviceFactory) and the interface it should return
(eg ITelevision) at runtime.
public IDeviceFactory<ifaceInstantiateDeviceFactory(strin g type, string
iface)
{
IDeviceFactory<ifacefactory = new type<iface>();
return factory;
}
Thanks,
Peter