good / evil [good wins :) - Resolved]
Is it possible or even good or bad practice to code a class so that it can serialize itself?
I have a class that currently only serializes one of its data members (an array). But how about this...
VB Code:
<Serializable()> Public Class X
Shared Function LoadNewObject(ByVal path As String) As X
Dim binser As BinaryFormatter = New BinaryFormatter
Dim input As Stream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)
Dim temp As X
temp = binser.Deserialize(input)
input.close()
Return temp
End Function
Public Sub SaveSelf(ByVal path As String)
Dim binser As BinaryFormatter = New BinaryFormatter
Dim output As Stream = New FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.None)
binser.Serialize(output, Me)
output.Close()
End Sub
End Class
Your thoughts please.