public bool Equals(my.game.PlayerV1 lhs, my.game.PlayerV2 rhs) { if (Object.ReferenceEquals(lhs, rhs)) { return(true); } if (Object.ReferenceEquals(lhs, null) || Object.ReferenceEquals(rhs, null)) { return(false); } return (lhs.id == rhs.id && lhs.name == rhs.name && vec3Cmp.Equals(lhs.pos, rhs.pos) && lhs.inventory.SequenceEqual(rhs.inventory, itemCmp) && lhs.quests.SequenceEqual(rhs.quests, questCmp) ); }
static void Main(string[] args) { PlayerComparer plyCmp = new PlayerComparer(); var pv1 = new my.game.PlayerV1(); pv1.id = 1; pv1.age = 22; pv1.factor = 2.0f; pv1.name = "pv1"; var itm = new my.game.Item(); itm.id = 11; itm.level = 321110; itm.type = 3; pv1.inventory.Add(itm); itm = new my.game.Item(); itm.id = 12; pv1.inventory.Add(itm); var qst = new my.game.Quest(); qst.id = 50; qst.name = "quest1"; qst.description = "There are something unusual..."; pv1.quests.Add(qst); var bytes = new byte[4096]; var stream = new adata.ZeroCopyBuffer(bytes); Int32 buf_len = 0; // serialize buf_len = pv1.SizeOf(); pv1.Write(stream); var pv1_other = new my.game.PlayerV1(); // deserialize pv1_other.Read(stream); stream.Clear(); var pv2 = new my.game.PlayerV2(); // forward compat (old data, new struct) pv2.Read(stream); Debug.Assert(plyCmp.Equals(pv1, pv2)); stream.Clear(); pv1 = new my.game.PlayerV1(); // backward compat (new data, old struct) pv2.id = 6543; pv2.name = "pv2"; pv2.friends.Add(2); pv2.friends.Add(100); buf_len = pv2.SizeOf(); pv2.Write(stream); pv1.Read(stream); Debug.Assert(plyCmp.Equals(pv1, pv2)); Console.WriteLine("done."); }