序列化第三方结构

时间:2013-12-03 20:47:22

标签: c# serialization struct

我正在编写一个简单的图形应用程序(使用Cairo)。我有以下基类:

[Serializable()]
public abstract class Shape : ICairoDrawable
{
    public PointD Start { get; set; }
    public PointD End { get; set; }

    public Color Filling { get; set; }
    public Color Outline { get; set; }

    public Shape(PointD start, PointD end, Color outline, Color fill)
    {
        Filling = fill;
        Outline = outline;
        Start = start;
        End = end;
    }

    public abstract void Draw(Context context);
}

和许多派生类如

[Serializable()]
public class Line : Shape
{
    public Line(PointD start, PointD end, Color outline, Color fill)
        : base(start, end, outline, fill)
    {
    }

    public override void Draw(Context context)
    {
        ...
    }
}

当尝试序列化(使用BinaryFormatter)运行时创建的形状列表时,我遇到了以下问题:PointD是在Cairo库中定义并高度使用的结构,所以我既不能添加{{ 1}}直接归属于它,也不是从它派生并使用我自己的结构。同样适用于Serializable

那么,可能的解决方法是什么?

0 个答案:

没有答案
相关问题