문제

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; }
}
도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top