EDN Admin
Well-known member
I have a class which has some specific properties
Some are serializable and some are not
The proerties which are not serializable, I have marked them <Nonserialized()>
I have used both XML and Binary Formatter But cannot serialize them
Please help me!!!
I have these functionsPublic Module APIs
Public Sub SerializeOBJ(ByVal Obj As Object, File As String)
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, Obj)
WriteAllBytes(File, mem.ToArray, False)
End Sub
Public Function DeserializeOBJ(Of T)(File As String) As T
Dim obj As Byte() = ReadAllBytes(File)
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream(obj)
Return DirectCast(bf.Deserialize(mem), T)
End Function
Sub SerializeXML(Of T)(ByVal Obj As T, ByVal FileName As String)
Dim Serializer As New XmlSerializer(GetType(T))
Using Fs As New FileStream(FileName, FileMode.OpenOrCreate)
Serializer.Serialize(Fs, Obj)
End Using
End Sub
Function DeserializeXML(Of T)(ByVal FileName As String) As T
Try
Dim Deserializer As New XmlSerializer(GetType(T))
Dim FileStream As New IO.FileStream(FileName, FileMode.Open)
Dim MyRectangle As T = CType(Deserializer.Deserialize(FileStream), T)
FileStream.Close()
FileStream.Dispose()
Return MyRectangle
Catch ex As Exception
Return Nothing
End Try
End Function
End Module
Please help me!! I have lots of objects and i have to serialize all of them
---------------------Do the Impossible--------------------- Great Software at http://atosoft.webs.com/
View the full article
Some are serializable and some are not
The proerties which are not serializable, I have marked them <Nonserialized()>
I have used both XML and Binary Formatter But cannot serialize them
Please help me!!!
I have these functionsPublic Module APIs
Public Sub SerializeOBJ(ByVal Obj As Object, File As String)
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, Obj)
WriteAllBytes(File, mem.ToArray, False)
End Sub
Public Function DeserializeOBJ(Of T)(File As String) As T
Dim obj As Byte() = ReadAllBytes(File)
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream(obj)
Return DirectCast(bf.Deserialize(mem), T)
End Function
Sub SerializeXML(Of T)(ByVal Obj As T, ByVal FileName As String)
Dim Serializer As New XmlSerializer(GetType(T))
Using Fs As New FileStream(FileName, FileMode.OpenOrCreate)
Serializer.Serialize(Fs, Obj)
End Using
End Sub
Function DeserializeXML(Of T)(ByVal FileName As String) As T
Try
Dim Deserializer As New XmlSerializer(GetType(T))
Dim FileStream As New IO.FileStream(FileName, FileMode.Open)
Dim MyRectangle As T = CType(Deserializer.Deserialize(FileStream), T)
FileStream.Close()
FileStream.Dispose()
Return MyRectangle
Catch ex As Exception
Return Nothing
End Try
End Function
End Module
Please help me!! I have lots of objects and i have to serialize all of them
---------------------Do the Impossible--------------------- Great Software at http://atosoft.webs.com/
View the full article