private void VisitedDeserialize( Action <object> Set, SerializeInfo deserializer) { var LastFrom = From; var Fr = BitConverter.ToInt32(D_Data, From); From += 4; if (deserializer.CanStoreInVisit == false) { if (Fr == -2) { return; } Set(deserializer.Deserializer()); return; } ObjectContainer VisitedObj; switch (Fr) { case -1: VisitedObj = new ObjectContainer() { ObjHashCode = LastFrom }; Visitor.BinaryInsert(VisitedObj); VisitedObj.obj = deserializer.Deserializer(); Set(VisitedObj.obj); return; case -2: return; } VisitedObj = new ObjectContainer() { ObjHashCode = Fr }; VisitedObj = Visitor.BinarySearch(VisitedObj).Value; if (VisitedObj.obj == null) { AtLast += () => Set(VisitedObj.obj); } else { Set(VisitedObj.obj); } }
private void VisitedSerialize( object obj, SerializeInfo serializer) { if (obj == null) { S_Data.Write(Byte_Int_N_2, 0, 4); return; } if (serializer.CanStoreInVisit == false) { S_Data.Write(Byte_Int_N_1, 0, 4); serializer.Serializer(obj); return; } var VisitedObj = new ObjectContainer() { ObjHashCode = obj.GetHashCode(), TypeHashCode = serializer.TypeHashCode }; var VisitedPos = Visitor.BinaryInsert(ref VisitedObj); if (VisitedPos > -1) { #if DEBUG if (VisitedObj.obj.GetType() != obj.GetType()) { throw new Exception("Type of visited object is wrong" + "\nMain: " + obj.GetType().ToString() + "\nVisited: " + VisitedObj.obj.GetType().ToString()); } #endif S_Data.Write(BitConverter.GetBytes(VisitedObj.FromPos), 0, 4); return; } #if DEBUG VisitedObj.obj = obj; #endif VisitedObj.FromPos = (int)S_Data.Position; S_Data.Write(Byte_Int_N_1, 0, 4); serializer.Serializer(obj); }