Here's a C# class I'm serializing to XML, currently with System.Xml.Serialization.XmlSerializer:
public class Stuff
{
// ...
[XmlElement("things")]
public List<Thing> Things { get; set; }
}
Is there any way to control, at serialization time, whether or not to serialize each individual Thing in the list? (For example, calling a predicate on each Thing to determine whether or not it should be included.)
Note: I've read a lot about the "ShouldSerialize*" trick from other questions, but that seems to apply only at the property level — that is, serialize the whole list, or none of it. What I want is to decide that for each individual member of my list. Solution doesn't have to use XmlSerializer if there's a better way to go about it.