Example #1
0
        /// <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);
        }
Example #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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
 /// <summary>
 /// Deletes all items from registry
 /// </summary>
 public virtual void Clear()
 {
     m_Data = new RegistryDictionary <T>(); //atomic
 }
Example #6
0
 /// <summary>
 /// Deletes all items from registry
 /// </summary>
 public virtual void Clear()
 {
     m_Data = new RegistryDictionary <T>(m_CaseSensitive); //atomic
 }
Example #7
0
 public Registry(bool caseSensitive)
 {
     m_CaseSensitive = caseSensitive;
     m_Data          = new RegistryDictionary <T>(caseSensitive);
 }