If I define ShouldSerialize* for current type property, it works. But it doesn’t work if I specify base type property. The same for *Specified
[XmlInclude(typeof(SingleEventGroup))]
[XmlInclude(typeof(MultipleEventsGroup))]
public abstract class EventsGroup
{
public List<int> EventsIds { get; set; }
public string Name { get; set; }
}
public class SingleEventGroup : EventsGroup
{
public bool ShouldSerializeName()
{
return false; //it is still serialized
}
}
The XmlSerializer looks for the method on the .DeclaringType of your member
Name, not on the .ReflectedType. This is why it doesn’t work.