开发者

Exclude an object during serialization with XmlSerializer

开发者 https://www.devze.com 2023-02-14 23:50 出处:网络
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 Ca

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.

[Seriali开发者_如何学运维zable]
[XmlRoot("Cart")]
public class Cart : ICart
{
    // Public Properties
    [DefaultValue("")]
    public string ID { set; get; }

    [XmlIgnore()]
    [NonSerialized]
    public CartSerializer Serializer = new CartSerializer(this);
}


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

    [XmlIgnore]  
    public string AnyProperty 
    {
        get;
        set;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消