Gav mig på serialization i .Net med VB2005 men det blir liksom inte mycket data i filen. Skit bakom spakarna (som så ofta).Serialization
cStateMachines innehåller ett antal PLCStateMachine
cStateMachineStates håller ett antal nycklar och strängar
och cInstances håller några PLCStateMachineInstance
Blir en del data i filen men vid återläsning finns inga object i cStateMachines.
Någon som kan tipsa ?
<code>
Public Class cPLCStateInfo : Inherits cPLC
<Serializable()> Private Class PLCStateMachine
Public iID As Integer
Public sDescription As String
Public cStateMachineStates As System.Collections.SortedList
Public cInstances As System.Collections.SortedList
Public Sub New(ByVal ID As Integer)
iID = ID
cStateMachineStates = New System.Collections.SortedList
cInstances = New System.Collections.SortedList
End Sub
End Class
<Serializable()> Private Class PLCStateMachineInstance
Public sVarName As String
Public lIndexGroup As Long
Public lIndexOffset As Long
Public iCurrentStateNo As Short
Public sComment As String
<NonSerialized()> Public oVNodeL As TreeNode
<NonSerialized()> Public oVNodeR As TreeNode
End Class
Private cStateMachines As System.Collections.SortedList
Public Sub New()
MyBase.New("", 801)
cStateMachines = New System.Collections.SortedList
End Sub
Public Sub Serialize()
Try
Dim fs As New FileStream(Application.StartupPath & "\DataFile.dat", FileMode.Create)
Dim formatter As New BinaryFormatter
Try
formatter.Serialize(fs, cStateMachines)
Catch ex As SerializationException
MessageBox.Show(ex.ToString)
AppLogFile.LogException(ex)
Finally
fs.Close()
End Try
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString)
AppLogFile.LogException(ex)
End Try
End Sub
Public Sub DeSerialize()
Dim fs As New FileStream(Application.StartupPath & "\DataFile.dat", FileMode.Open)
Try
Dim formatter As New BinaryFormatter
cStateMachines = DirectCast(formatter.Deserialize(fs), SortedList)
Catch ex As SerializationException
MessageBox.Show(ex.ToString)
AppLogFile.LogException(ex)
Finally
fs.Close()
End Try
End Sub
.
.
.
</code>Sv: Serialization
Anropar man bara rätt instans så går det mycket bättre.
:)