System.Drawing.Color objects apparently won\'t serialize with XmlSerializer. What is the best way to xml serialize colors?
You could write a simple wrapper class for Color that exposes the ARGB values as properties. You could translate to/from the colors using from/to ARGB conversions (see docs). Something like:
[Serializable]
public class ColorWrapper
{
private Color color;
public ColorWrapper (Color color)
{
this.color = color;
}
public ColorWrapper()
{
// default constructor for serialization
}
public int Argb
{
get
{
return color.ToARGB();
}
set
{
color = Color.FromARGB();
}
}
}
Probably want an accessor for the color too!
Benefit of this is that the class can be used in all places you have to serialize colors. If you want to make the XML readable (rather than an arbitrary ARGB integer) you could use the to/from HTML methods as described by balabaster.