related to xml Serialization Process

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
Hi guys, again looking for some fine wisdom from the pros.
I have two classes i am trying to serialize. i have already got them serialized and know how to do it, just looking for advise

Q1: Does it matter if i use 'Dim' 'Private' 'Property',
best example of what im on about, is the first block of code
does it need to be Private and Public ReadOnly Property?
does it need to be a Property or can i just usePublic?


VB.NET:
[COLOR=#0000cd]Public Class[/COLOR] CarList
    [COLOR=#0000cd]Private[/COLOR] _Car_Make [COLOR=#0000cd]As New List[/COLOR]([COLOR=#0000cd]Of [/COLOR]CarMake)
    [COLOR=#0000cd]Public ReadOnly Property [/COLOR]CarMake [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of [/COLOR]CarMake) [COLOR=#008000]
          Get
               Return _Car_make
          end get
[/COLOR][COLOR=#0000ff]End Class[/COLOR]



VB.NET:
[COLOR=#0000cd]Public Class[/COLOR] CarMake
   [COLOR=#0000cd] Public Property[/COLOR] Name [COLOR=#0000cd]As String[/COLOR]
    [COLOR=#0000cd]Private[/COLOR] _Model [COLOR=#0000cd]As New [/COLOR]List([COLOR=#0000cd]Of String[/COLOR])
    [COLOR=#0000cd]Private [/COLOR]_Colour [COLOR=#0000cd]As New [/COLOR]List([COLOR=#0000cd]Of String[/COLOR])

    [COLOR=#0000cd]Public ReadOnly Property [/COLOR]Model [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of String[/COLOR])
        [COLOR=#0000cd]Get[/COLOR]
            [COLOR=#0000cd]Return [/COLOR]_Model
        [COLOR=#0000cd]End Get[/COLOR]
   [COLOR=#0000cd] End Property

    Public ReadOnly Property[/COLOR] Colour [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of String[/COLOR])
        [COLOR=#0000cd]Get
            Return[/COLOR] _Colour
        [COLOR=#0000cd]End Get
    End Property
End Class[/COLOR]


Q2: I have used XML tags PURELY for layout of the XML doc as it was loaded with nodes, are they good to use and will it make any difference in the serialization process.
eg reasons to not use them?

VB.NET:
[COLOR=#0000cd]Public Class[/COLOR] DamageListCollection
    [COLOR=#0000cd]Dim [/COLOR]m_Services [COLOR=#0000cd]As New [/COLOR]List([COLOR=#0000cd]Of[/COLOR] Service)
    <XmlElement("Services")> _
    [COLOR=#0000cd]Public Property[/COLOR] Services [COLOR=#0000cd]As[/COLOR] List([COLOR=#0000cd]Of[/COLOR] Service)
       [COLOR=#0000cd] Get
            Return[/COLOR] m_Services
        [COLOR=#0000cd]End Get
        Set[/COLOR](value [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of [/COLOR]Service))
            m_Services = value
        [COLOR=#0000cd]End Set
    End Property
End Class[/COLOR]

[COLOR=#0000cd]Public Class Service
    Private[/COLOR] m_List [COLOR=#0000cd]As New [/COLOR]List([COLOR=#0000cd]Of [/COLOR]Damagelist)

    <XmlAttribute("Name")> _
    [COLOR=#0000cd]Public Property[/COLOR] Name[COLOR=#0000cd] As String[/COLOR]

    <XmlAttribute("ID")> _
[COLOR=#0000cd]    Public Property[/COLOR] ID [COLOR=#0000cd]As Byte[/COLOR]

    <XmlArray("DamageList")> _
    [COLOR=#0000cd]Public Property[/COLOR] List [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of [/COLOR]Damagelist)
        [COLOR=#0000cd]Get
            Return[/COLOR] m_List
        [COLOR=#0000cd]End Get
        Set[/COLOR](value [COLOR=#0000cd]As [/COLOR]List(Of Damagelist))
            m_List = value
        [COLOR=#0000cd]End Set
    End Property
End Class

Public Class[/COLOR] Damagelist
   [COLOR=#0000cd] Dim[/COLOR] m_Items [COLOR=#0000cd]As New [/COLOR]List([COLOR=#0000cd]Of [/COLOR]Damage)

    <XmlAttribute("Name")> _
    [COLOR=#0000cd]Public Property[/COLOR] Name [COLOR=#0000cd]As String[/COLOR]

    <XmlAttribute("Statement")> _
    [COLOR=#0000cd]Public Property[/COLOR] statement [COLOR=#0000cd]As String[/COLOR]

    <XmlAttribute("ID")> _
    [COLOR=#0000cd]Public Property[/COLOR] ID [COLOR=#0000cd]As Byte[/COLOR]



    <XmlArray("Damage")> _
   [COLOR=#0000cd] Public Property[/COLOR] Items [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of[/COLOR] Damage)
        [COLOR=#0000cd]Get
            Return[/COLOR] m_Items
        [COLOR=#0000cd]End Get
        Set[/COLOR](value [COLOR=#0000cd]As [/COLOR]List([COLOR=#0000cd]Of [/COLOR]Damage))
            m_Items = value
        [COLOR=#0000cd]End Set
    End Property
End Class

Public Class[/COLOR] Damage
   [COLOR=#0000cd] Dim[/COLOR] _Name [COLOR=#0000cd]As String[/COLOR]
    [COLOR=#0000cd]Dim [/COLOR]_ID [COLOR=#0000cd]As Byte[/COLOR]

    <XmlAttribute("Name")> _
    [COLOR=#0000cd]Public Property[/COLOR] Name [COLOR=#0000cd]As String[/COLOR]
        [COLOR=#0000cd]Get
            Return[/COLOR] _Name
        [COLOR=#0000cd]End Get
        Set[/COLOR](value As String)
            _Name = [COLOR=#0000cd]value[/COLOR]
        [COLOR=#0000cd]End Set
    End Property[/COLOR]

    <XmlAttribute("ID")> _
    [COLOR=#0000cd]Public Property[/COLOR] ID [COLOR=#0000cd]As Byte[/COLOR]
        [COLOR=#0000cd]Get
            Return[/COLOR] _ID
        [COLOR=#0000cd]End Get
        Set[/COLOR](value [COLOR=#0000cd]As Byte[/COLOR])
            _ID = value
        [COLOR=#0000cd]End Set
    End Property[/COLOR]
[COLOR=#0000cd]End Class[/COLOR]

The main reason for this thread is to ask would it be better to use a class or a structure Any info will help loads

EDIT: the reason i am looking at this is because msdn says
"Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created."
which this pretty much applies to me
 
Last edited:
Back
Top