У меня есть производный класс, который наследуется от класса баса, который рисует круг
public BraceHole(Brace brace, Vertex centerPoint, double diameter, VDrawI5.vdEntities entities) : base(centerPoint, diameter / 2, entities)
{
this.brace = brace;
this.centerPoint = centerPoint;
this.radius = diameter/2;
}
Я пытаюсь сериализовать этот класс, используя двоичную сериализацию.
Я сериализую это так:
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("brace", brace, typeof(Brace));
info.AddValue("radius", radius, typeof(double));
info.AddValue("centerPoint", centerPoint, typeof(Vertex));
}
С сериализацией все в порядке, но когда я ее десериализую, как показано ниже: Я возвращаю поля данных (скобка, радиус и центральная точка) в порядке; но я не получаю круг обратно! Я подозреваю, что это потому, что я не десериализую базовый класс. Как бы я ни пытался, я не знаю, как это сделать!
protected BraceHole(SerializationInfo info, StreamingContext context)
{
try {
brace = (Brace)info.GetValue("brace", typeof(Brace));
radius = (double)info.GetValue("radius", typeof(double));
centerPoint = (Vertex)info.GetValue("centerPoint", typeof(Vertex));
}
catch{}
}
Мой вопрос в том, как я могу десериализовать это. Я ищу что-то подобное, это возможно?
protected BraceHole(SerializationInfo info, StreamingContext context) : base(centerPoint, radius, entities)
{
VdProControl.VdProControl vectorDraw = (VdProControl.VdProControl)context.Context;
VDrawI5.vdEntities entities = vectorDraw.ActiveDocument.Entities;
try {
brace = (Brace)info.GetValue("brace", typeof(Brace));
radius = (double)info.GetValue("radius", typeof(double));
centerPoint = (Vertex)info.GetValue("centerPoint", typeof(Vertex));
}
catch{}
}