I have a pair of COM objects in two different places that follow the exact same interface (except for namespace, so nsA.ICOMObject
looks the same as nsB.ICOMObject
with the exception that nsA
is replaced by nsB
all over the place).
Which of the objects I will be using is decided on application startup and can be held easily enough. The issue that I have is how to do all of this without duplication. I know that for method calls I can do it simply with a dynamic
object but that still leaves me an issue with event handling.
Currently I would do:
if (useObjectA)
{
theCOMObject.eventToHandle += new nsA.eventHandler(method);
}
else
{
theCOMObject.eventToHandle += new nsB.eventHandler(method);
}
all over the place and for just a namespace change this seems a little silly.
Am I right that there is an easier way to do this and what is it? There are literally hundreds of methods/properties/events on these objects so creating an object that takes all the pain away would be very hard work.
Many Thanks
Gareth