1
我正在尋找一種方法來序列化包含不同類型的對象,如字符串,整數和集合的結構。包含列表的VB.NET Serealize結構
我有這樣的數據結構:
Dim database as New mainStruct
<Serializable()> Structure mainStruct
Public name As String
Public address As String
Public Shared bookings As IList(Of booking) = New List(Of booking)
End Structure
<Serializable()> Structure booking
Public id As Integer
Public category As String
Public description As String
End Structure
運行串行:
Dim fs As FileStream = New FileStream("x.bin", FileMode.OpenOrCreate)
Dim serial As New XmlSerializer(GetType(mainStruct))
serial.Serialize(fs, database)
fs.Close()
輸出只包含所有非集合變量,如:
<?xml version="1.0"?>
<mainStruct xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>foo</name>
<address>bar</address>
</mainStruct>
我怎麼能序列化預訂集合,而不使用GetType(List(Of booking))創建單獨的文件?
謝謝!
很高興我能幫到你!祝你的項目好運! –