Protobuf-net - How to add same field in inherited class without causing backward version compatibility

Viewed 15

Let's say I have below classes structure:

Base class:

[ProtoContract]
[ProtoInclude(10, typeof(Store))]
[ProtoInclude(11, typeof(House))]
public abstract class Address
{
   [ProtoMember(1)] Id ;
   [ProtoMember(2)] string Country;
   [ProtoMember(3)] string Pincode;
}

Child Class 1:

[ProtoContract]
public class Store: Address
{
   [ProtoMember(1)] int StoreUniqueid;
   [ProtoMember(2)] string StoreUniqueValue;
   [ProtoMember(3)] string Pincode;
}

Child Class 2:

[ProtoContract]
public class House : Address
{
   [ProtoMember(1)] int HouseArea;
}

Now, I have a situation where I need to introduce the "Pincode" property of Store class to the House Class.

What should be the ideal way to address this issue to maintain the backward compatibility?

Option 1: Move the Pincode property of the Store class to the Address (base) class. However, this may create a backward compatibility issue since we have to remove the Pincode property from the Store class.

Option 2: Add another same property(Pincode) inside the House class as below (Not sure whether this would be a right approach.)

[ProtoContract]
public class House: Address
{
   [ProtoMember(1)] int HouseArea;
   [ProtoMember(2)] string Pincode;
}
0 Answers
Related