Hi all,
I am coding in
VB.NET and here I must use abstract class in my project. When I write to xml file in serialization, there was an error generating the XML document. The following is the code:
Public Class Form1
Inherits System.Windows.Forms.Form
Public c4 As New Class4()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c1 As New Class1()
c1.a = "2"
c1.b = " 3"
Dim c2 As New Class2()
c1.cc = c2
c2.m = "4"
c4.items.Add(c1)
c4.save()
End Sub
End Class
Public Class Class1
Public a As String
Public b As String
Public cc As Class3
End Class
Public Class Class2
Inherits Class3
Public m As String
End Class
Imports System.Xml.Serialization
Imports System.IO
Public Class Class4
<XmlIgnore()> Public items As New ArrayList()
Public Property c1() As Class1()
Get
Dim c1array(items.Count - 1) As Class1
items.CopyTo(c1array)
Return c1array
End Get
Set(ByVal Value As Class1())
items.Clear()
If Not Value Is Nothing Then
Dim c1 As Class1
For Each c1 In Value
items.Add(c1)
Next
End If
End Set
End Property
Public Sub save()
Dim ser As New XmlSerializer(Me.GetType)
Dim writer As New StreamWriter("c:\file.xml")
'error information appeared in this statement
ser.Serialize(writer, Me)
writer.Close()
End Sub
End Class
Thanks a lot in advance,
Haiying