我有一个简单的类结构;
Public Class Country
Public CountryCode As String = ""
End Class
Public Class AllCountries
Inherits List(Of Country)
Public name As String
End Class
Public MyAc As New AllCountries
Public Sub Serialize()
Dim myC As New Country
myC.CountryCode = "be"
MyAc.Add(myC)
MyAc.name = "yadda"
Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(AllCountries))
Using Target As New FileStream("test.txt", FileMode.CreateNew)
Serializer.Serialize(Target, MyAc)
Target.Close()
End Using
End Sub
当我对此序列化时,XML不包含“名称”字段和值;
<?xml version="1.0"?>
<ArrayOfCountry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Country>
<CountryCode>be</CountryCode>
</Country>
</ArrayOfCountry>
如果删除“继承列表(国家)”,则名称值将保存在XML中。但是我不知道如何解决这个问题。谢谢