Hi, I'm trying to break down the problem to a more simple description.
I'm using an external class library, which exposes 4 base classes, all very similar, sometimes derived from each other.
During the execution I'm called back on several delegate functions, all carrying an "object Sender", which contains the initial object of one of the 4 base classes, called on an API function before.
Sample (more or less pseudo code):
classA oA = new classA();
oA.API(callbackA);
Later on the callback is called, carrying oA as "Sender".
void callbackA(object Sender) {
classA oA = (classA)Sender;
oA.API2(xxx);
....
}
The approach above works fine. Now I wanted to extend it to the remaining 3 classes. Because the handling in their callbacks is rather identical, I didn't want to replicate the code another 3 times, but would rather make callbackA ready to deal with Senders of type classB, classC and classD.
I cannot achieve this in any usefull solution. Is anybody able to help me?
UPDATE: Because I did get lot of answer pointing to "is" - "is" is not a solution. I need to have ONE variable, capable of having multiple types. Dynamic casting?