In my code I make use of many small enums:
enum UserRequest : byte { Burp=1, Sneeze=2, Fart=3 }
I often need to validate integer input before converting it to this enum.
bool valid_input = Enum.IsDefined(typeof(UserRequest), user_byte_value);
This approach does not work when the enum makes use of the FlagsAttribute; Enum.IsDefined cannot automatically combine flags to make a specified value. However, I've been able to work around not needing FlagsAttribute.
However, TIL that Eazfuscator.NET's obfuscation breaks Enum.IsDefined. I knew it was a possibility, but I was hoping it wouldn't since it's not in the System.Reflection namespace (reportedly though, it makes heavy use of System.Reflection).
So I'm wondering if anyone knows any good alternatives. I'm specifically after the following:
- Allows checking if an integer is in a specified enum.
- Compatible with .NET Framework 2.0 and the Mono Framework.
- Survives obfuscation without explicitly disabling it (using attributes or some GUI tool).