public NodeEnumerator(ListDictionary list) { this.list = list; this.version = list.version; this.start = true; this.current = null; }
/// <summary>Creates an empty <see cref="T:System.Collections.Specialized.ListDictionary" /> using the default comparer.</summary> public ListDictionary() { this.count = 0; this.version = 0; this.comparer = null; this.head = null; }
private ListDictionary.DictionaryNode FindEntry(object key, out ListDictionary.DictionaryNode prev) { if (key == null) { throw new ArgumentNullException("key", "Attempted lookup for a null key."); } ListDictionary.DictionaryNode next = this.head; prev = null; if (this.comparer == null) { while (next != null) { if (key.Equals(next.key)) { break; } prev = next; next = next.next; } } else { while (next != null) { if (this.comparer.Compare(key, next.key) == 0) { break; } prev = next; next = next.next; } } return(next); }
public NodeKeyValueEnumerator(ListDictionary list, bool isKeys) { this.list = list; this.isKeys = isKeys; this.version = list.version; this.start = true; this.current = null; }
public void Reset() { if (this.version != this.list.version) { throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion")); } this.start = true; this.current = null; }
/// <summary>Adds an entry with the specified key and value into the <see cref="T:System.Collections.Specialized.ListDictionary" />.</summary> /// <param name="key">The key of the entry to add. </param> /// <param name="value">The value of the entry to add. The value can be null. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key" /> is null. </exception> /// <exception cref="T:System.ArgumentException">An entry with the same key already exists in the <see cref="T:System.Collections.Specialized.ListDictionary" />. </exception> public void Add(object key, object value) { ListDictionary.DictionaryNode prev; ListDictionary.DictionaryNode dictionaryNode = this.FindEntry(key, out prev); if (dictionaryNode != null) { throw new ArgumentException("key", "Duplicate key in add."); } this.AddImpl(key, value, prev); }
public bool MoveNext() { this.FailFast(); if (this.current == null && !this.isAtStart) { return(false); } this.current = ((!this.isAtStart) ? this.current.next : this.dict.head); this.isAtStart = false; return(this.current != null); }
private void AddImpl(object key, object value, ListDictionary.DictionaryNode prev) { if (prev == null) { this.head = new ListDictionary.DictionaryNode(key, value, this.head); } else { prev.next = new ListDictionary.DictionaryNode(key, value, prev.next); } this.count++; this.version++; }
void ICollection.CopyTo(Array array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if (index < 0) { throw new ArgumentOutOfRangeException("index", SR.GetString("ArgumentOutOfRange_NeedNonNegNum")); } for (ListDictionary.DictionaryNode node = this.list.head; node != null; node = node.next) { array.SetValue(this.isKeys ? node.key : node.value, index); index++; } }
public bool MoveNext() { if (this.version != this.list.version) { throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion")); } if (this.start) { this.current = this.list.head; this.start = false; } else if (this.current != null) { this.current = this.current.next; } return(this.current != null); }
/// <summary>Removes the entry with the specified key from the <see cref="T:System.Collections.Specialized.ListDictionary" />.</summary> /// <param name="key">The key of the entry to remove. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key" /> is null. </exception> public void Remove(object key) { ListDictionary.DictionaryNode dictionaryNode2; ListDictionary.DictionaryNode dictionaryNode = this.FindEntry(key, out dictionaryNode2); if (dictionaryNode == null) { return; } if (dictionaryNode2 == null) { this.head = dictionaryNode.next; } else { dictionaryNode2.next = dictionaryNode.next; } dictionaryNode.value = null; this.count--; this.version++; }
/// <summary>Gets or sets the value associated with the specified key.</summary> /// <returns>The value associated with the specified key. If the specified key is not found, attempting to get it returns null, and attempting to set it creates a new entry using the specified key.</returns> /// <param name="key">The key whose value to get or set. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key" /> is null. </exception> public object this[object key] { get { ListDictionary.DictionaryNode dictionaryNode = this.FindEntry(key); return((dictionaryNode != null) ? dictionaryNode.value : null); } set { ListDictionary.DictionaryNode prev; ListDictionary.DictionaryNode dictionaryNode = this.FindEntry(key, out prev); if (dictionaryNode != null) { dictionaryNode.value = value; } else { this.AddImpl(key, value, prev); } } }
public bool MoveNext() { if (this.version != this.list.version) { throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion")); } if (this.start) { this.current = this.list.head; this.start = false; } else if (this.current != null) { this.current = this.current.next; } return (this.current != null); }
/// <summary>Removes all entries from the <see cref="T:System.Collections.Specialized.ListDictionary" />.</summary> public void Clear() { this.head = null; this.count = 0; this.version++; }
public DictionaryNode(object key, object value, ListDictionary.DictionaryNode next) { this.key = key; this.value = value; this.next = next; }
public void Reset() { this.FailFast(); this.isAtStart = true; this.current = null; }