SiberianGuy
SiberianGuy

Reputation: 25312

XmlSerializer ShouldSerialize* doesn't work for base type property

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

Answers (1)

Seb
Seb

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

Related Questions