【发布时间】:2017-06-20 09:50:12
【问题描述】:
我正在寻找一种方法来序列化包含不同类型对象(如字符串、整数和集合)的结构。
我有这个数据结构:
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)) 创建单独文件的情况下序列化预订集合?
谢谢!
【问题讨论】:
标签: vb.net serialization struct xml-serialization ixmlserializable