Best solution for XmlSerializer and System.Drawing.Color

前端 未结 4 1398
耶瑟儿~
耶瑟儿~ 2020-12-01 12:36

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

4条回答
  •  再見小時候
    2020-12-01 13:04

    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...

提交回复
热议问题