Reputation: 25312
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
}
}
Upvotes: 1
Views: 1977
Reputation: 2715
The XmlSerializer looks for the method on the .DeclaringType of your member Name
, not on the .ReflectedType. This is why it doesn't work.
Upvotes: 3