A general query
Im serialising a person object with the following member variables
Class Person
Private _forenames As String
Private _surname As String
Private _dob As Date
Private _marital_status As MaritalStatus
'Public Get and Set Properties here for each of the above
' I'll not detail them all to save space but Ill show attributes
<XmlElementAttribute(Elementname:="forename")> _
<XmlElementAttribute(Elementname:="surname")> _
<XmlElementAttribute(Elementname:="dob")> _
<XmlElementAttribute(Elementname:="marital_status" )> _
Public Sub New()
End New
Public Enum MaritalStatus
Single,
Married
End Enum
End Class
Say I create a new person:
Dim Dickster as New Person
Dickster.Forename = "mike"
Dickster.Surname = "smith"
It will Serialise as
<Person>
<forename>mike</forename>
<surname>smith</surname>
<dob>1900-01-01</dob>
<marital_status>Single>
</Person>
BUT I didnt set the <dob> and <marital_status> node so i dont want them
to show .
So to work round this i wrapped dates and enumerations in individual
classes...
This was grand but a bit OTT...
Then I discovered ....Specified As Boolean
Private _marital_status As MaritalStatus
Private _marital_statusSpecified As Boolean = False
<XmlElementAttribute(ElementName:="marital_status" )> _
Public Property marital_status() As MaritalStatus
Get
Return _marital_status
End Get
Set(ByVal Value As MaritalStatus)
_marital_status = Value
If Value Is Nothing Then
_marital_statusSpecified = False
Else
_marital_statusSpecified = True
End If
End Set
End Property
<XmlIgnore()> _
Public Property marital_statusSpecified() As Boolean
Get
Return _marital_statusSpecified
End Get
Set(ByVal Value As Boolean)
_marital_statusSpecified = Value
End Set
End Property
Likewise for Dates and Ints
Is there any thoughts about using this means to hide the serilisation
of unset values ?
Thanks
Dickster