1

String、Integer、Collectionsなどの異なるオブジェクトを含む構造をシリアル化する方法を探しています。シリアライザを実行している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 Of booking)を使用して別々のファイルを作成することなく、予約コレクションをシリアライズしますか?

ありがとうございます!シリアル化すべてのクラス/構造の保存についてインスタンスであり、メンバーは、インスタンスの一部ではないので、共有

答えて

0

共有メンバーがシリアライズされません。

あなたの構造にインスタンスプロパティを追加し、あなたが行くために良いことがあります:

Public Property bookingList As IList(Of booking) 
    Get 
     Return mainStruct.bookings 
    End Get 
    Set(value As IList(Of booking) 
     mainStruct.bookings = value 
    End Set 
End Property 

あなたがタグはあなただけのプロパティにXmlArray attributeを適用することができます<bookings>呼ばれるようにしたい場合:

<XmlArray("bookings")> _ 
Public Property bookingList As IList(Of booking) 
    ...same code as above... 
End Property 
+0

私は助けることができてうれしい!あなたのプロジェクトに幸運を祈る! –

関連する問題