I've created three classes:
cLesson cStage cActivity
Right now, I'm experimenting with serialising list properties and have the following code for two of my classes setup:
cLesson.vb
<Serializable()> _
<System.Xml.Serialization.XmlInclude(GetType(List(Of cStage)))> _
Public Class cLesson
Private lStages As New List(Of cStage)
Public Sub addStage(sStage As String)
Dim oStage As New cStage
oStage.Title = sStage
lStages.Add(oStage)
End Sub
Public Sub listStages()
For Each oStage In lStages
MsgBox(oStage.Title)
Next
End Sub
End Class
cStage.vb
<Serializable> _
Public Class cStage
Private sTitle As String
Public Property Title() As String
Get
Return sTitle
End Get
Set(ByVal Value As String)
sTitle = Value
End Set
End Property
End Class
Form1.vb - Serialise Calls
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xml_serializer As New Xml.Serialization.XmlSerializer(GetType(cLesson))
'Word document pointers
Dim pDoc As String
'Open master document
Dim fdFile As SaveFileDialog = New SaveFileDialog
fdFile.Title = "Save Reading Resource"
fdFile.Filter = "Dat Files|*.dat"
fdFile.RestoreDirectory = True
If fdFile.ShowDialog = Windows.Forms.DialogResult.OK Then
pDoc = fdFile.FileName
Dim stream_writer As New StreamWriter(pDoc, False)
Try
xml_serializer.Serialize(stream_writer, oLesson)
stream_writer.Close() ' close the file
Catch ex As Exception
MsgBox(ex.InnerException.ToString)
End Try
End If
End Sub
However, when I run this program, I'm not getting the list property appearing in the XML.
In the end, I want a lesson with a list of stages, each stage of which can have a list of activities.
Any advice would be great appreciated. I've looked online a lot and haven't been able to find anything to help.
UPDATE 1
Making the list public allows it to be serialised. However, I'd prefer it to be private.
Public lStages As New List(Of cStage)