Empowering Enums(www.kodefuguru.com)

submitted by KodefuGuruKodefuGuru(2818) 8 months, 4 days ago

When reading Steve Smith’s articles on enums on ASP.NET Alliance and his blog, I couldn’t help but think of a different approach to the issue. I’ve seen, used, and coded the enum class pattern before (and it works well), but we have new language features today to encourage reuse and empower true enums. I am going to show you techniques that won’t require significant changes to your code if you have an existing base of enums.

3 comments |category: |Views: 252

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by dpetersondpeterson(4397) 8 months, 3 days ago +1

I like your approach, but what about handling the undefined enum Steve showed in his ShouldNowAllowInvalidValue test? I'm guessing his point was that undefined values didn't throw exceptions, whereas a class would most likely throw a NullReferenceException. Or was your article just focusing on adding custom attributes to the Enum?
Thanks for sharing!

Reply

posted by KodefuGuruKodefuGuru(2818) replied to dpetersondpeterson(4397), 8 months, 3 days ago 0

Thanks dpeterson! To answer your question, you would do exactly what Steve did but with the extension methods. Check Enum.IsDefined and throw an exception if it isn't (if this is the desired behavior).

Reply

posted by dpetersondpeterson(4397) replied to KodefuGuruKodefuGuru(2818), 8 months, 3 days ago 0

Thanks for the followup!

Reply

information Login or create an account to comment on this story