/// <summary> /// 从指定的主键中移除指定的值。 /// </summary> /// <param name="key">指定的主键。</param> /// <param name="value">指定的值。</param> /// <returns>是否移除成功。</returns> public bool Remove(TKey key, TValue value) { GXLinkedListRange <TValue> range = default(GXLinkedListRange <TValue>); if (m_Dictionary.TryGetValue(key, out range)) { for (LinkedListNode <TValue> current = range.First; current != null && current != range.Terminal; current = current.Next) { if (current.Value.Equals(value)) { if (current == range.First) { LinkedListNode <TValue> next = current.Next; if (next == range.Terminal) { m_LinkedList.Remove(next); m_Dictionary.Remove(key); } else { m_Dictionary[key] = new GXLinkedListRange <TValue>(next, range.Terminal); } } m_LinkedList.Remove(current); return(true); } } } return(false); }
/// <summary> /// 处理事件结点。 /// </summary> /// <param name="sender">事件源。</param> /// <param name="e">事件参数。</param> private void HandleEvent(object sender, T e) { bool noHandlerException = false; GXLinkedListRange <EventHandler <T> > range = default(GXLinkedListRange <EventHandler <T> >); if (m_EventHandlers.TryGetValue(e.Id, out range)) { LinkedListNode <EventHandler <T> > current = range.First; while (current != null && current != range.Terminal) { m_CachedNodes[e] = current.Next != range.Terminal ? current.Next : null; current.Value(sender, e); current = m_CachedNodes[e]; } m_CachedNodes.Remove(e); } else if (m_DefaultHandler != null) { m_DefaultHandler(sender, e); } else if ((m_EventPoolMode & EventPoolMode.AllowNoHandler) == 0) { noHandlerException = true; } ReferencePool.Release(e); if (noHandlerException) { throw new GXException(Utility.Text.Format("Event '{0}' not allow no handler.", e.Id.ToString())); } }
/// <summary> /// 获取多值字典中指定主键的范围。 /// </summary> /// <param name="key">指定的主键。</param> /// <returns>指定主键的范围。</returns> public GXLinkedListRange <TValue> this[TKey key] { get { GXLinkedListRange <TValue> range = default(GXLinkedListRange <TValue>); m_Dictionary.TryGetValue(key, out range); return(range); } }
/// <summary> /// 检查多值字典中是否包含指定值。 /// </summary> /// <param name="key">要检查的主键。</param> /// <param name="value">要检查的值。</param> /// <returns>多值字典中是否包含指定值。</returns> public bool Contains(TKey key, TValue value) { GXLinkedListRange <TValue> range = default(GXLinkedListRange <TValue>); if (m_Dictionary.TryGetValue(key, out range)) { return(range.Contains(value)); } return(false); }
internal Enumerator(GXLinkedListRange <T> range) { if (!range.IsValid) { throw new GXException("Range is invalid."); } m_GXLinkedListRange = range; m_Current = m_GXLinkedListRange.m_First; m_CurrentValue = default(T); }
/// <summary> /// 获取事件处理函数的数量。 /// </summary> /// <param name="id">事件类型编号。</param> /// <returns>事件处理函数的数量。</returns> public int Count(int id) { GXLinkedListRange <EventHandler <T> > range = default(GXLinkedListRange <EventHandler <T> >); if (m_EventHandlers.TryGetValue(id, out range)) { return(range.Count); } return(0); }
/// <summary> /// 向指定的主键增加指定的值。 /// </summary> /// <param name="key">指定的主键。</param> /// <param name="value">指定的值。</param> public void Add(TKey key, TValue value) { GXLinkedListRange <TValue> range = default(GXLinkedListRange <TValue>); if (m_Dictionary.TryGetValue(key, out range)) { m_LinkedList.AddBefore(range.Terminal, value); } else { LinkedListNode <TValue> first = m_LinkedList.AddLast(value); LinkedListNode <TValue> terminal = m_LinkedList.AddLast(default(TValue)); m_Dictionary.Add(key, new GXLinkedListRange <TValue>(first, terminal)); } }
/// <summary> /// 从指定的主键中移除所有的值。 /// </summary> /// <param name="key">指定的主键。</param> /// <returns>是否移除成功。</returns> public bool RemoveAll(TKey key) { GXLinkedListRange <TValue> range = default(GXLinkedListRange <TValue>); if (m_Dictionary.TryGetValue(key, out range)) { m_Dictionary.Remove(key); LinkedListNode <TValue> current = range.First; while (current != null) { LinkedListNode <TValue> next = current != range.Terminal ? current.Next : null; m_LinkedList.Remove(current); current = next; } return(true); } return(false); }
/// <summary> /// 尝试获取多值字典中指定主键的范围。 /// </summary> /// <param name="key">指定的主键。</param> /// <param name="range">指定主键的范围。</param> /// <returns>是否获取成功。</returns> public bool TryGetValue(TKey key, out GXLinkedListRange <TValue> range) { return(m_Dictionary.TryGetValue(key, out range)); }