0
votes

I have a data contract that serializing using protobuf-net.

[ProtoContract]    
public class Cat
{
    [ProtoMember(1)]
    public Friend[] Friends { get; set; }
}

Last time a decide to refactor them and move some properties to base class, like:

[ProtoContract]    
public class Cat : Animal
{
    // other props
}

public abstract class Animal
{
    [ProtoMember(1)]
    public Friend[] Friends { get; set; }
}

After this I found that property Friends not deserializing from previous seralized data. How can I perform refactoring like this without breaking change?

1

1 Answers

0
votes

I'm not at a PC to verify this, but you could try adding:

[ProtoPartialMember(1, "Friends")]

to Cat's class definition. If this doesn't work, next thing to try would be:

    RuntimeTypeModel.Default[typeof(Cat)]
.Add(1, " Friends ");

(Before serializing)

If neither of those work, let me know and I'll find a better option when I'm not on a plane :)

Worst case would be to redeclare the member:

[ProtoMember(1)]
public new Friend[] Friends {
    get { return base.Friends;}
    set { base.Friends = value; }
}