Convert a string into an enum(blogs.msdn.com)

submitted by jonasjonas(2215) 4 years, 1 month ago

Tim Sneath writes some C# to convert a string into an enum.

2 comments |category: |Views: 26

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 DanRigsbyDanRigsby(1880) 4 years ago 0

You could also try this:
http://www.danrigsby.com/blog/index.php/2007/12/16/missing-static-generic-alternatives-in-enum-class/

It would allow you to do like so:

Color color = EnumUtilities.ParseEnum<Color>("Red");

Instead of:

Color color = (Color)Enum.Parse(typeof(Color), "Red");

Reply

posted by cheriancherian(35) 4 years ago 0

Take a look at this implementation with attributes.

http://www.gigpeppers.com/blog/post/Convert-enum-to-string-with-attributes.aspx

Reply

information Login or create an account to comment on this story