I am encountering a problem which is how do I convert input strings like "RED" to the actual Color type Color.Red
in C#. Is there a good way to do this?
I could think of using a switch statement and cases statement for each color type but I don't think that is clever enough.
(Use my method if you want to accept HTML-style hex colors.)
Since the OP mentioned in a comment that he's using
Microsoft.Xna.Framework.Graphics.Color
rather thanSystem.Drawing.Color
you can first create a System.Drawing.Color then convert it to aMicrosoft.Xna.Framework.Graphics.Color
For transferring colors via xml-strings I've found out: