Friend Class SerializeSomething (Of T)
Friend Function SerializeFontObject(ByVal oObject As T) As [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL]
Dim bf As New [URL="http://www.dotnet247.com/247reference/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.aspx"]BinaryFormatter[/URL]
Dim mem As New [URL="http://www.dotnet247.com/247reference/System/IO/MemoryStream.aspx"]MemoryStream[/URL]
Try
bf.Serialize(mem, oObject)
Return [URL="http://www.dotnet247.com/247reference/System/Convert.aspx"]Convert[/URL].ToBase64String(mem.ToArray())
Catch
Return [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL].Empty
Finally
mem.Close()
End Try
End Function
Friend Function DeserializeFontObject(ByVal sString As String) As T
Dim bf As New [URL="http://www.dotnet247.com/247reference/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.aspx"]BinaryFormatter[/URL]
Dim mem As New [URL="http://www.dotnet247.com/247reference/System/IO/MemoryStream.aspx"]MemoryStream[/URL]([URL="http://www.dotnet247.com/247reference/System/Convert.aspx"]Convert[/URL].FromBase64String(sString))
Try
Return DirectCast(bf.Deserialize(mem), T)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
End class