Make your classes serializable.

I’ve done a little of this in the past, and I’m about to do it today. Each time I have to look it up, so in hopes of finding it a little quicker or maybe remembering how this time, I’ll post it here.

From: MSDN – Custom Serialization


_
Public Class MyObject
Implements ISerializable
Public n1 As Integer
Public n2 As Integer
Public str As String

Public Sub New()
End Sub

Protected Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
n1 = info.GetInt32("i")
n2 = info.GetInt32("j")
str = info.GetString("k")
End Sub 'New

_
Public Overridable Sub GetObjectData(ByVal info As _
SerializationInfo, ByVal context As StreamingContext)
info.AddValue("i", n1)
info.AddValue("j", n2)
info.AddValue("k", str)
End Sub
End Class

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>