There is new feature introduced in C# 7.1 called generic pattern matching. One of the examples I found looks like this:
void Attack(IWeapon weapon, IEnemy enemy)
{
switch (weapon)
{
case Sword sword:
// process sword attack
break;
case Bow bow:
// process bow attack
break;
}
}
But from my perspective it's a piece of incorrect design, which violates the second SOLID principle(open-close). I can't even think of the case where this might be needed, from my understanding if you came to situation when you need such switch, then you are doing something very wrong. From other hand, if this feature was added to language, there have to be a strong reason of doing so. So the question is - when would you need this assuming you're not creating poor architecture.
I agree that you can abuse it to violate open/closed, but you wouldn't use it in the way you have with your example (by taking in an interface).
Instead, consider a situation where you deserialize an object.
You might have a chat program and people can send messages, or images (pseudo code)
You could put this into a
switchinstead. It's still open closed because you can write additional types that extendIImage/ITextMessage.You'd have to alter the fundamental functionality of the program to support things that aren't both of those. Or you could have an else
{ doSomeDefaultBehaviour(); }