I have a complex object that I am serializing, and I would like to omit
elements that have a default value.
For example, if I have a class as follows
Public Class Test
Private m_Name As String = "George"
Private m_Active As Boolean = False
Private m_Address As String
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
Public Property Active() As Boolean
Get
Return m_Active
End Get
Set(ByVal Value As Boolean)
m_Active = Value
End Set
End Property
Public Property Address() As String
Get
Return m_Address
End Get
Set(ByVal Value As String)
m_Address = Value
End Set
End Property
End Class
If Name is "George" when I serialize the object then I don't want this
element to be included in the output. Similarly, if Active is "False" when
the object is serialized, then I don't want that element included in the
output either. Anything different, and they should be included.
Is there a way to do this, perhaps by tagging the property/element in some
way? I am using VS2003.
TIA
Charles