I assume the problem is transferring old data? If so, then v2 can do it for you; however , I would also be personally turned on to say "meh, Age is # 3, Id remains # 2" (I do not see huge advantages when changing this number).
But as an example for a more general case:
var oldModel = RuntimeTypeModel.Create(); // "false" here means "don't apply the normal rules; I'll tell you what to do" oldModel.Add(typeof(Person), false).Add("Name", "Id"); var newModel = RuntimeTypeModel.Create(); // "true" here means it will read from the attributes etc newModel.Add(typeof(Person), true); // now: load from an old file, and write to a new: var obj = oldModel.Deserialize(inFile, null, typeof(Person)); newModel.Serialize(outFile, obj);
Having 2 different instances of RuntimeTypeModel
with different configurations, you can apply all kinds of odd transfers between data. But then again - using this just to make Age
# 2 seem like a massive overkill. In fact, I would just make my class:
[ProtoContract] class Person { [ProtoMember(1)] public string Name {get;set:} [ProtoMember(2)] public int Id {get;set;} [ProtoMember(3)] public int Age {get;set;} }
And look! They are magical in order!
source share