// // Private helpers // private void Reset() { _entriesArray = new ArrayList(); _entriesTable = new Hashtable(_keyComparer); _nullKeyEntry = null; _version++; }
/// <devdoc> /// <para> Removes the entry at the specified index of the /// <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para> /// </devdoc> protected void BaseRemoveAt(int index) { if (_readOnly) { throw new NotSupportedException(SR.CollectionReadOnly); } string?key = BaseGetKey(index); if (key != null) { // remove from hashtable _entriesTable.Remove(key); } else { // null key -- special case // null out special 'null key' entry _nullKeyEntry = null; } // remove from array _entriesArray.RemoveAt(index); _version++; }
// // Methods to add / remove entries // /// <devdoc> /// <para>Adds an entry with the specified key and value into the /// <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para> /// </devdoc> protected void BaseAdd(string?name, object?value) { if (_readOnly) { throw new NotSupportedException(SR.CollectionReadOnly); } NameObjectEntry entry = new NameObjectEntry(name, value); // insert entry into hashtable if (name != null) { if (_entriesTable[name] == null) { _entriesTable.Add(name, entry); } } else { // null key -- special case -- hashtable doesn't like null keys if (_nullKeyEntry == null) { _nullKeyEntry = entry; } } // add entry to the list _entriesArray.Add(entry); _version++; }
private void Reset(int capacity) { _entriesArray = new ArrayList(capacity); _entriesTable = new Hashtable(capacity, _keyComparer); _nullKeyEntry = null; _version++; }
/// <devdoc> /// <para>Sets the value of the first entry with the specified key in the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> /// instance, if found; otherwise, adds an entry with the specified key and value /// into the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> /// instance.</para> /// </devdoc> protected void BaseSet(string?name, object?value) { if (_readOnly) { throw new NotSupportedException(SR.CollectionReadOnly); } NameObjectEntry?entry = FindEntry(name); if (entry != null) { entry.Value = value; _version++; } else { BaseAdd(name, value); } }
/// <devdoc> /// <para>Removes the entries with the specified key from the /// <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para> /// </devdoc> protected void BaseRemove(string?name) { if (_readOnly) { throw new NotSupportedException(SR.CollectionReadOnly); } if (name != null) { // remove from hashtable _entriesTable.Remove(name); // remove from array for (int i = _entriesArray.Count - 1; i >= 0; i--) { if (_keyComparer.Equals(name, BaseGetKey(i))) { _entriesArray.RemoveAt(i); } } } else { // null key -- special case // null out special 'null key' entry _nullKeyEntry = null; // remove from array for (int i = _entriesArray.Count - 1; i >= 0; i--) { if (BaseGetKey(i) == null) { _entriesArray.RemoveAt(i); } } } _version++; }
// // Access by name // /// <devdoc> /// <para>Gets the value of the first entry with the specified key from /// the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para> /// </devdoc> protected object?BaseGet(string?name) { NameObjectEntry?e = FindEntry(name); return((e != null) ? e.Value : null); }
// // Access by name // /// <devdoc> /// <para>Gets the value of the first entry with the specified key from /// the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para> /// </devdoc> protected object?BaseGet(string?name) { NameObjectEntry?e = FindEntry(name); return(e?.Value); }