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
I use a serializable font, somewhat different from Elad's.
In my serializable data-entities I hide ([XmlIgnore]
) the property with the Font
type and expose the property with the SerializableFont
type, which is "eaten" by the serializer.
Note that this is applicable to the XmlSerializer
only.
///
/// Font descriptor, that can be xml-serialized
///
public class SerializableFont
{
public string FontFamily { get; set; }
public GraphicsUnit GraphicsUnit { get; set; }
public float Size { get; set; }
public FontStyle Style { get; set; }
///
/// Intended for xml serialization purposes only
///
private SerializableFont() { }
public SerializableFont(Font f)
{
FontFamily = f.FontFamily.Name;
GraphicsUnit = f.Unit;
Size = f.Size;
Style = f.Style;
}
public static SerializableFont FromFont(Font f)
{
return new SerializableFont(f);
}
public Font ToFont()
{
return new Font(FontFamily, Size, Style,
GraphicsUnit);
}
}