Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude an object during serialization with XmlSerializer

I'm attempting to serialize an object but I would like to exclude one of the objects inside it. I've tried [NonSerialized] and it is still attempting to serialize it when I call XmlSerializer on a Cart object.

[Serializable]
[XmlRoot("Cart")]
public class Cart : ICart
{
    // Public Properties
    [DefaultValue("")]
    public string ID { set; get; }

    [XmlIgnore()]
    [NonSerialized]
    public CartSerializer Serializer = new CartSerializer(this);
}
like image 939
J. Mitchell Avatar asked Mar 07 '11 00:03

J. Mitchell


1 Answers

You may try to use XmlIgnore like this, it works!

    [XmlIgnore]  
    public string AnyProperty 
    {
        get;
        set;
    }
like image 184
David Avatar answered Nov 09 '22 20:11

David