2009-04-11 4 views
0

나는 잘 serialize하는 속성 목록이 포함 된 클래스가 있습니다. 그러나 나는 나에게 서브 클래스Serializable 클래스 컬렉션

예 XML

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

내가 메인 클래스를 직렬화 때 수행하는 방법을 잘 모르겠어요를 제공하기 위해 다른 클래스의 컬렉션을 포함하는 속성 중 하나를해야합니다.

현재 내 클래스를 직렬화하는이 명령을 사용

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

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

답변

0

당신은 단순히 아래의 컬렉션 클래스를 만들기 Property3

의 모음

인 VideoOptions 클래스의 속성을 가지고해야합니다.

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 tem에는 params가없는 생성자가 있습니다 (XML 직렬화에 필요함). Xmlserializer 클래스는 문제없이 지정한 형식으로 직렬화 및 비 직렬화합니다.

희망이 도움이되었습니다.

관련 문제