I am serializing an object with only properties being stored. It has a parent inheritance but I made sure the serialized attributes are of different indexes with the numbers.
[ProtoContract]
[ProtoInclude(597, typeof(DesiredProto))]
[ProtoInclude(598, typeof(RandomClass1Proto))]
[ProtoInclude(599, typeof(RandomClass2Proto))]
[ProtoInclude(600, typeof(RandomClass3Proto))]
public class BaseProto
{
protected string mName = "";
protected string mOwner = "";
protected VObjectType mVType; //this is an enumeration!
public BaseProto(){}
[ProtoMember(1)]
public String Name
{
get { return mName; }
set { mName = value;}
}
[ProtoMember(2)]
public String Owner
{
get { return mOwner; }
set { mOwner = value;}
}
[ProtoMember(3)]
public VObjectType VType
{
get { return mVType; }
set { mVType = value;}
}
}
and then DesiredProto:
[ProtoContract]
public class DesiredProto : BaseProto
{
protected DestinationType mDestType;
protected string mAddress = "";
public DesiredProto()
{
}
[ProtoMember(1)]
public DestinationType DestType //this is an enumeration
{
get { return mDestType; }
set { mDestType = value;}
}
[ProtoMember(2)]
public String Address
{
get { return mAddress; }
set { mAddress = value;}
}
}
Now the really weird part is that the serialization seemingly is completely functional. Whenever I serialize and deserialize this "DesiredProto" it works, if I ignore the error. Lastly this isn't the full code snippet for these classes, they are much much longer, but hopefully the error is somehow contained in this.
DestinationType
? – Marc Gravell[ProtoMember(2)] public string Address {get;set;}
- the compiler does basically exactly the same as you did (behind the scenes), but without the risk of making typos (using the wrong field, etc) – Marc Gravell