Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best solution for XmlSerializer and System.Drawing.Color

Tags:

System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml serialize colors?

like image 391
P a u l Avatar asked Dec 17 '08 22:12

P a u l


1 Answers

The simplest method uses this at it's heart:

String HtmlColor = System.Drawing.ColorTranslator.ToHtml(MyColorInstance);

It will just convert whatever the color is to the standard hex string used by HTML which is just as easily deserialized using:

Color MyColor = System.Drawing.ColorTranslator.FromHtml(MyColorString);

That way you're just working with bog standard strings...

like image 124
BenAlabaster Avatar answered Oct 31 '22 10:10

BenAlabaster