How to XmlSerialize System.Drawing.Font class

后端 未结 5 1926
心在旅途
心在旅途 2021-01-11 17:15

The classSystem.Drawing.Font is not XML Serializable since it doesn\'t have a default (empty) constructor.
Is there some work around or alternative way to

5条回答
  •  清歌不尽
    2021-01-11 17:55

    Try the DataContractSerializer.

            Font fnt = new Font("Arial", 1);
            MemoryStream data = new MemoryStream();
            DataContractSerializer dcs = new DataContractSerializer(typeof(Font), new[] { typeof(FontStyle), typeof(GraphicsUnit) });
            dcs.WriteObject(data, fnt);
            string xml = Encoding.UTF8.GetString(data.ToArray());
    

提交回复
热议问题