rbwhitaker / CSharpPlayersGuideEarlyAccess

A place to track issues with the C# Player's Guide for patches and future editions
19 stars 0 forks source link

Stringifying and Parsing Enumerations #662

Closed rbwhitaker closed 1 year ago

rbwhitaker commented 2 years ago

The book currently falls a bit short in explaining how to turn user input into enumeration values and how to turn enumeration values into strings. That should be remedied.

I think this means making a whole new section specifically about converting between the two, and it likely has a great deal of overlap with this blog post: http://csharpplayersguide.com/blog/2022/05/22/parsing-enumerations/

Some of the essential items I want to point out are:

  1. There are some "automatic" ways to do it, but they've got their limits.
  2. The manual way to do it is maybe with switch expressions, which go great with enumerations.
  3. There are "automatic" ways to do it, but they use typeof, Type, and generics. I think the book can show examples of these, but probably needs to defer on explaining them in great detail.

Does this require moving the typeof operator discussion forward? I think it does. But I also think that's probably fine.

rbwhitaker commented 1 year ago

This has been added.