示例#1
0
        public SavableInstance getInstanceById(int id)
        {
            SavableInstanceRegistration reference = _registrations.Find(e => { return(e.id == id); });

            if (reference != null)
            {
                return(reference.instance);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// 重新分配ID
        /// </summary>
        /// <param name="id"></param>
        /// <param name="instance"></param>
        public void reallocate(int id, SavableInstance instance)
        {
            SavableInstanceRegistration r = _registrations.Find(e => { return(e.id == id); });

            if (r != null)
            {
                r.instance = instance;
            }
            else
            {
                if (data.idPool.Remove(id))
                {
                    _registrations.Add(new SavableInstanceRegistration(id, instance));
                }
                else
                {
                    //从来都没分配过这样的ID,那么你说有就有吧。
                    _registrations.Add(new SavableInstanceRegistration(id, instance));
                }
            }
        }