Hi,
I need help on serializing /deserializing a class.
My class:
<Serializable()>
Public Class Scanner
Public Property ScannerID As String
Public Property ScannerText As String
Private Sub New()
End Sub
Public Sub New(ByVal sScanID As String, ByVal sScanText As String)
ScannerID = sScanID
ScannerText = sScanText
End Sub
Public Overrides Function toString() As String
Return ScannerID.ToString & ", " & ScannerText.ToString
End Function
End Class
In a module
Public lstScanner As New List(Of Scanner)
I use the list as Datasource for a ComboBox
The list is filled from a ComboBox text and a TextBox
lstScanner.Add(New Scanner(cboScanID.Text, txtScanText.Text))
My goal is to save the data on application exit and reuse them on application start.
I succeed to save the data but cannot figure out how to deserialize them.
Public Sub SaveScanner(ByVal pathFile As String, ByVal className As List(Of Scanner))
Dim objStreamWriter As New StreamWriter(pathFile)
Dim xsSerialize As New XmlSerializer(className.GetType)
xsSerialize.Serialize(objStreamWriter, className)
objStreamWriter.Close()
End Sub
Thank you in advance
What I have tried:
Public Sub SaveScanner(ByVal pathFile As String, ByVal className As List(Of Scanner))
Dim objStreamWriter As New StreamWriter(pathFile)
Dim xsSerialize As New XmlSerializer(className.GetType)
xsSerialize.Serialize(objStreamWriter, className)
objStreamWriter.Close()
End Sub