Best solution for XmlSerializer and System.Drawing.Color

前端 未结 4 1401
耶瑟儿~
耶瑟儿~ 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条回答
  •  猫巷女王i
    2020-12-01 13:00

    Final working version:

    Color clrGrid = Color.FromArgb(0, 0, 0);
    [XmlIgnore]
    public Color ClrGrid 
    {
        get { return clrGrid; }
        set { clrGrid = value; }
    }
    [XmlElement("ClrGrid")]
    public string ClrGridHtml
    {
        get { return ColorTranslator.ToHtml(clrGrid); }
        set { ClrGrid = ColorTranslator.FromHtml(value); }
    }
    

提交回复
热议问题