Tony Vitabile
Tony Vitabile

Reputation: 8594

How to keep an inherited property of a child class from serializing

I have a base class that a number of other classes inherit from. The base class supports XML serialization and has a property that is serializaed.

I would like to keep that same property from serializing in one of the child classes. Is this possible? How do I do it?

Thanks

Tony

Upvotes: 0

Views: 178

Answers (2)

Ashwin Chandran
Ashwin Chandran

Reputation: 1467

You can use the XmlIgnoreAttribute. See this article.

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlignore.aspx

Upvotes: 2

mgnoonan
mgnoonan

Reputation: 7200

Decorate the property you want to hide with the [XmlIgnore] attribute:

[Serializable]
[XmlRoot(ElementName = "Customer")]
public class SimplifiedCustomer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [XmlIgnore]
    public long CustomerId { get; set; }
}

Upvotes: 1

Related Questions