This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
Original Post: Working with Enums
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
Geoff wrote a whole bunch of code for dealing with Enums. Enums are annoying because you can cast any integer to an Enum type and you will not get an exception message (at least in version 1.0 and 1.1). Geoff's solution uses the IsDefined static method on Enum, but using the IsDefined method really sucks.
If I had a Flags enum, I'd write something like this (the one assumption I make is that the Flags enum is written with values in ascending order):