ISerializable

To gain even more control over the serialization process, you can implement the ISerializable interface and a special constructor:

 <Serializable()> _ Class MyData Implements ISerializable Dim s As String = "Wahoo!" Dim n As Integer = 6 Public Property MyString() As String Get Return s End Get Set s = Value n = s.Length End Set End Property Public ReadOnly Property Length() As Integer Get Return n End Get End Public Public Overrides Sub New() ... End Sub #Region Implementation of ISerializable Public Overrides Sub New(info As ISerializationInfo, _ context As StreamingContext) ' Get value from name/value pairs s = info.GetString("MyString") ' Cache the string's length n = s.Length End Sub Public Sub GetObjectData(info As SerializationInfo, ...

Get Windows Forms Programming in Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.