示例#1
0
        public bool RegisterObject(SaveableObject obj)
        {
            if (obj.Id != 0)
            {
                return(false);
            }

            if (!Attribute.IsDefined(obj.GetType(), typeof(SerializableAttribute)))
            {
                return(false);
            }

            obj.Id = m_currentId++;
            RegisteredObjects.Add(m_currentId, obj);

            if (RegisteredTypes.TryGetValue(obj.ClassId, out Type val))
            {
                if (val != obj.GetType())
                {
                    throw new ArgumentException();
                }
            }
            else
            {
                RegisteredTypes.Add(obj.ClassId, obj.GetType());
            }

            return(true);
        }
示例#2
0
        public void Resume(Stream stream)
        {
            RegisteredTypes.Clear();
            RegisteredObjects.Clear();
            BinaryFormatter bf = new BinaryFormatter();

            RegisteredTypes = (Dictionary <uint, Type>)bf.Deserialize(stream);
            byte[] aCount = new byte[sizeof(int)];
            stream.Read(aCount, 0, sizeof(int));
            int count = BitConverter.ToInt32(aCount, 0);
            int i     = 0;

            while (i < count)
            {
                SaveableObject so = ResumeObject(stream) as SaveableObject;
                RegisteredObjects.Add(so.Id, so);
                ++i;
            }
        }
示例#3
0
 public bool UnregisterObject(SaveableObject obj)
 {
     return(RegisteredObjects.Remove(obj.Id));
 }