Question

I have a custom class that inherits a PictureBox control and when I deserialize the object I am missing all the basic properties like "Name" for example. Here is the class.

    [ProtoContract]
[ProtoInclude(100,typeof(PictureBox))]
class Card : PictureBox
{        
    [ProtoMember(1)]
    public string CardId { get; set; }

    [ProtoMember(2)]
    public string CardName { get; set; }

    [ProtoMember(3)]
    public string CardColor { get; set; }

    [ProtoMember(4)]
    public string CardType { get; set; }

    [ProtoMember(5)]
    public string CardRarity { get; set; }

    [ProtoMember(6)]
    public bool Tapped { get; set; }

    [ProtoMember(7)]
    public bool Revealed { get; set; }
}
Était-ce utile?

La solution

One possibility (untested) if you can't modify the base class, is to reveal what you need:

[ProtoMember(8)]
public new string Name
{
    get { return base.Name; }
    set { base.Name = value; }
}

I am using this technique to apply my own attributes (or change DefaultAttribute value) to certain properties of standard controls, when making my own controls (to example, my own Label) and it seems to work.

Autres conseils

My understanding is that you might need a [ProtoContract] attribute on the base class also. http://www.codeproject.com/Articles/642677/Protobuf-net-the-unofficial-manual

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top