assuming the following XML structure:
<ROOT>
<ELEMENT>...</ELEMENT>
<ELEMENT>...</ELEMENT>
<ANOTHERELEMENT>...</ANOTHERELEMENT>
</ROOT>
I am deserializing all XML elements of type ELEMENT
into a List<ElementType>
via the following way:
[XmlElement("ELEMENT")]
public List<ElementType> Elements { get; set; }
So far so good, but now I need to control which objects of type ElementType
to serialize. This should be achieved by checking the objects' IsEnabled
property. Only objects with IsEnabled = true
should be serialized. This property is not part of the XML document but can be set via the program's GUI. As far as I can see, ShouldSerialize[MemberName]
won't do the trick in this case.
Initially, I was thinking about using some sort of adaptor property but wanted to see if there is an elegant way of achieving my goal.
Unfortunately, making changes to the XML structure is not really an alternative.
Thanks in advance, guys. Any help will be greatly appreciated. Cheers, Zettel.