2009-04-11 13 views
0

私はクラスを持っています。しかし、私は私のサブのクラスシリアライズ可能クラスコレクション

例XML

<VideoOptions> 
<property1>value1</property1> 
<property2>value2</property2> 
<property3> 
    <item> 
     <property1>value1</property1> 
    </item> 
    <item> 
     <property1>value1</property1> 
    </item> 
</property3> 
</VideoOptions> 

を与えるために別のクラスのコレクションを含むようにこれらのプロパティのいずれかが必要私はメインクラスをシリアル化するときそれを達成するかどうかはわかりません。

現在、私はあなたが単にProperty3

のコレクションは以下のように、コレクションクラスを作成しているVideoOptionsクラスのプロパティを持っている必要があります

Dim oXS As XmlSerializer = New XmlSerializer(GetType(VideoOptions)) 

     Dim strW As New StringWriter 
     oXS.Serialize(strW, Me) 
     VideoOptionsAsXML = strW.ToString 

答えて

0

私のクラスをシリアル化するために、このコマンドを使用します。

Public Class Property3Collection 
    Inherits CollectionBase 

    Public Function Add(ByVal item As Property3Item) As Integer 
     Return Me.List.Add(item) 
    End Function 

    Default Public ReadOnly Property Item(ByVal index As Integer) As Object 
     Get 
      Return CType(Me.List.Item(index), SingleItem) 
     End Get 
    End Property 
End Class 

は、あなたの商品のためのクラスを持って

Public Class Property3Item 
'Add in Item property 
End Class 

Public Sub AddPropertyItem 
    Dim newCol as New Property3Collection 
    newCol.Add(New Property3Item) 
End Sub 

がいる限り、あなたのVideoOptionsクラス

Public Property Property3() As Property3Collection 
     Get 

     End Get 
     Set(ByVal Value As Property3) 

     End Set 
    End Property 

にプロパティを追加するには、Property3Collectionクラスを構築プロパティ3I (XMLのシリアル化に必要な)paramsを持たないコンストラクタがある場合、Xmlserializerクラスはこれを問題なく指定した形式にシリアル化して逆シリアル化します。

希望すると便利です。

関連する問題