This little scenario popped into my head, and had me stumped for a while.
Given the interfaces IA and IB,
interface IA { } interface IB { }
and the generic method AandB which accepts an object of a type which implements both IA and IB.
void AandB<T>(T anb) where T : IA, IB { }
How can we call AandB in the following situation?
void Situation(IA a) { if (a is IB) { // AandB(a); ?? } }
Hint: You may be surprised how easy it is.
Update: Ouch, sorry all, I made a mistake, my solution didn't actually work! Seeking a new one. I'm back to thinking this is impossible (excluding using reflection).
8 Comments
