No, there is no compile time check - it is legal to have a / case switch that only processes some of the named values. You could turn it on, but there are some problems.
First, it is fully valid (unfortunately) for an enumeration value that does not have any "named" values:
enum Foo { Bar = 0, Baz = 1 } ... Foo nastyValue = (Foo) 50;
Given that any value is possible in the switch / case, the compiler may not know that you did not want to try to handle the unnamed value.
Secondly, this will not work with Flags enums - the compiler really does not know what values โโare intended for convenient combinations. That might have concluded, but that would have been a bit unpleasant.
Thirdly, this is not always what you want - sometimes you really only want to answer a few cases. I would not like to suppress warnings on a fairly regular basis.
You can use Enum.IsDefined to test this, but it is relatively inefficient.
I agree that all this is a little painful - enums are a bit of a nasty area when it comes to .NET :(
Jon skeet
source share