I have an xml file with elements that look like this (abbreviated for clarity):
<post id="1" tags="tag1 tag2 tag3 tag4" />
I want to map this to the following class using Xml Deserialization, but I can’t find a way to map the tags attribute to an actual List(Of String).
<Serializable()> _
<XmlRootAttribute("post")> _
Public Class Post
Private m_id As Integer
Private m_tags As String
<XmlAttribute("id")> _
Public Property Id() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
'<XmlAttribute("tags")> _
Public Property Tags() As List(Of String)
Get
Return m_tags
End Get
Set(ByVal value As List(Of String))
m_tags = value
End Set
End Property
End Class
Is there any way to override the default Deserialization?
I think the easiest thing to do is to have a
RawTagsget/set property which gets serialized, and aTagsreadonly property which parses the RawTags to aList<string>but gets ignored by the serializer: