예제 #1
0
파일: NameRegistry.cs 프로젝트: mjaric/nfx
        /// <summary>
        /// Unregisters item and returns true if it was unregistered, false if it did not exist
        /// </summary>
        public bool Unregister(T item)
        {
            lock (m_Sync)
            {
                if (!m_Data.ContainsKey(item.Name))
                {
                    return(false);
                }

                var data = new RegistryDictionary <T>(m_Data);
                data.Remove(item.Name);

                JustUnregistered(item);

                m_Data = data;
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Registers item and returns true if it was registered, false if this named instance already existed in the list
        /// </summary>
        public bool Register(T item)
        {
            lock (m_Sync)
            {
                if (m_Data.ContainsKey(item.Name))
                {
                    return(false);
                }

                var data = new RegistryDictionary <T>(m_CaseSensitive, m_Data);
                data.Add(item.Name, item);

                JustRegistered(item);

                m_Data = data;
            }

            return(true);
        }
예제 #3
0
파일: NameRegistry.cs 프로젝트: mjaric/nfx
        /// <summary>
        /// Unregisters item by name and returns true if it was unregistered, false if it did not exist
        /// </summary>
        public bool Unregister(string name)
        {
            lock (m_Sync)
            {
                T item;
                if (!m_Data.TryGetValue(name, out item))
                {
                    return(false);
                }

                var data = new RegistryDictionary <T>(m_Data);
                data.Remove(name);

                JustUnregistered(item);

                m_Data = data;
            }

            return(true);
        }
예제 #4
0
파일: NameRegistry.cs 프로젝트: mjaric/nfx
        /// <summary>
        /// Registers item and returns true if it was registered, false if this named instance already existed and was replaced
        /// </summary>
        public bool RegisterOrReplace(T item, out T existing)
        {
            lock (m_Sync)
            {
                var data = new RegistryDictionary <T>(m_Data);

                if (data.TryGetValue(item.Name, out existing))
                {
                    data[item.Name] = item;
                    JustReplaced(existing, item);
                }
                else
                {
                    existing = default(T);//safeguard
                    data.Add(item.Name, item);
                    JustRegistered(item);
                }

                m_Data = data;
            }

            return(existing == null);
        }
예제 #5
0
파일: NameRegistry.cs 프로젝트: mjaric/nfx
 /// <summary>
 /// Deletes all items from registry
 /// </summary>
 public virtual void Clear()
 {
     m_Data = new RegistryDictionary <T>(); //atomic
 }
예제 #6
0
 /// <summary>
 /// Deletes all items from registry
 /// </summary>
 public virtual void Clear()
 {
     m_Data = new RegistryDictionary <T>(m_CaseSensitive); //atomic
 }
예제 #7
0
 public Registry(bool caseSensitive)
 {
     m_CaseSensitive = caseSensitive;
     m_Data          = new RegistryDictionary <T>(caseSensitive);
 }