Search
Step 8: Implement serialization

Implement serialization of custom class members.

C#  Copy Code

protected override void SaveTo(
    System.IO.BinaryWriter writer, PersistContext ctx)
{
    base.SaveTo(writer, ctx);

    // Save the label using the standard .NET BinaryWriter
    writer.Write(label);

    // Save the image using the MindFusion.Diagramming built-in image saving code,
    // which stores the contents of shared images only once.
    ctx.SaveImage(icon);
}

protected override void LoadFrom(
    System.IO.BinaryReader reader, PersistContext ctx)
{
    base.LoadFrom(reader, ctx);

    label = reader.ReadString();
    icon = ctx.LoadImage();
}

Visual Basic  Copy Code

Protected Overrides Sub SaveTo( _
    ByVal writer As System.IO.BinaryWriter, ByVal ctx As PersistContext)

    MyBase.SaveTo(writer, ctx)
    ' Save the label using the standard .NET BinaryWriter
    writer.Write(fLabel)

    ' Save the image using the MindFusion.Diagramming built-in image saving code,
    ' which stores the contents of shared images only once.
    ctx.SaveImage(fIcon)

End Sub

Protected Overrides Sub LoadFrom( _
    ByVal reader As System.IO.BinaryReader, ByVal ctx As PersistContext)

    MyBase.LoadFrom(reader, ctx)

    fLabel = reader.ReadString()
    fIcon = ctx.LoadImage()

End Sub