Serialize and deserialize

  • Thread starter Thread starter Amsteel
  • Start date Start date
A

Amsteel

I got something like this in VB.Net

<Serializable()> Public Class YQProfileC
Inherits CollectionBase
Public Sub Save2File(ByVal FileName As String)
Dim IFormatter As New BinaryFormatter()
Dim FS As FileStream = New FileStream(FileName, FileMode.Create,
FileAccess.Write, FileShare.None)
IFormatter.Serialize(FS, Me)
FS.Close()
End Sub

Public Function LoadFromFile(ByVal FileName As String) As YQProfileC
Dim IFormatter As New BinaryFormatter()
Dim FS As FileStream = New FileStream(FileName, FileMode.Open,
FileAccess.Read, FileShare.None)
Return IFormatter.Deserialize(FS)
End Function
End Class

Now I got two problem here:
1.For some reason, the Root space name of the project needs to be changed
from YQV020 to YQV. But after that, how could I deserialize the old file.
2.What would have been done to deserialize the file if we want o change the
code from VB.net to C#.net? Please don't ask me why.

Thanks very much.


Amsteel
 
Amsteel,
1.For some reason, the Root space name of the project needs to be changed
from YQV020 to YQV. But after that, how could I deserialize the old file.
The following three part article covers binary serialization in detail:
http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I believe the third one discusses what to do if the namespace changes.
2.What would have been done to deserialize the file if we want o change the
code from VB.net to C#.net? Please don't ask me why.
Changing from VB.NET to C# should not effect anything, as long as both types
are "exactly" the same. For the change in the 'name' (version number really)
you can use the code in the above articles.

Hope this helps
Jay
 
Back
Top