Consider the following code :
private enum myEnum
{
A,
B
}
private void myMethod(myEnum m)
{
switch (m)
{
case myEnum.A:
//do stuff
break;
case myEnum.B:
//do stuff
break;
default:
throw new NotImplementedException(m.ToString());
}
}
If I ever add a third member C to myEnum, I will only be warned at runtime by a NotImplementedException
What I'd like to do is have the compiler warn me when there's a switch with unhandled cases and no default: case.
Is there a way to do that, or other solution to this problem, the ultimate goal being to be warned at compile-time that something is missing?