Пример #1
0
        //
        // Private helpers
        //

        private void Reset()
        {
            _entriesArray = new ArrayList();
            _entriesTable = new Hashtable(_keyComparer);
            _nullKeyEntry = null;
            _version++;
        }
Пример #2
0
 private void Reset(int capacity)
 {
     _entriesArray = new ArrayList(capacity);
     _entriesTable = new Hashtable(capacity, _keyComparer);
     _nullKeyEntry = null;
     _version++;
 }
 protected void BaseAdd(string name, object value)
 {
     if (this._readOnly)
     {
         throw new NotSupportedException(SR.GetString("CollectionReadOnly"));
     }
     NameObjectEntry entry = new NameObjectEntry(name, value);
     if (name != null)
     {
         if (this._entriesTable[name] == null)
         {
             this._entriesTable.Add(name, entry);
         }
     }
     else if (this._nullKeyEntry == null)
     {
         this._nullKeyEntry = entry;
     }
     this._entriesArray.Add(entry);
     this._version++;
 }
Пример #4
0
        /// <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++;
        }
Пример #5
0
        /// <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++;
        }
Пример #6
0
        //
        // 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++;
        }
Пример #7
0
        //
        // Access by index
        //

        /// <include file='doc\NameObjectCollectionBase.uex' path='docs/doc[@for="NameObjectCollectionBase.BaseGet1"]/*' />
        /// <devdoc>
        ///    <para>Gets the value of the entry at the specified index of
        ///       the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para>
        /// </devdoc>
        protected Object BaseGet(int index)
        {
            NameObjectEntry entry = (NameObjectEntry)_entriesArray[index];

            return(entry.Value);
        }
Пример #8
0
        //
        // Access by name
        //

        /// <include file='doc\NameObjectCollectionBase.uex' path='docs/doc[@for="NameObjectCollectionBase.BaseGet"]/*' />
        /// <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);
        }
Пример #9
0
        /// <devdoc>
        ///    <para>Gets the key of the entry at the specified index of the
        ///    <see cref='System.Collections.Specialized.NameObjectCollectionBase'/>
        ///    instance.</para>
        /// </devdoc>
        protected String BaseGetKey(int index)
        {
            NameObjectEntry entry = (NameObjectEntry)_entriesArray[index];

            return(entry.Key);
        }
        //
        // Access by index
        //

        /// <devdoc>
        ///    <para>Gets the value of the entry at the specified index of
        ///       the <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance.</para>
        /// </devdoc>
        protected object?BaseGet(int index)
        {
            NameObjectEntry entry = (NameObjectEntry)_entriesArray[index] !;   // no null entry added to the array

            return(entry.Value);
        }
 private void Reset()
 {
     this._entriesArray = new ArrayList();
     this._entriesTable = new Hashtable(this._keyComparer);
     this._nullKeyEntry = null;
     this._version++;
 }
 protected void BaseRemoveAt(int index)
 {
     if (this._readOnly)
     {
         throw new NotSupportedException(SR.GetString("CollectionReadOnly"));
     }
     string key = this.BaseGetKey(index);
     if (key != null)
     {
         this._entriesTable.Remove(key);
     }
     else
     {
         this._nullKeyEntry = null;
     }
     this._entriesArray.RemoveAt(index);
     this._version++;
 }
 protected void BaseRemove(string name)
 {
     if (this._readOnly)
     {
         throw new NotSupportedException(SR.GetString("CollectionReadOnly"));
     }
     if (name != null)
     {
         this._entriesTable.Remove(name);
         for (int i = this._entriesArray.Count - 1; i >= 0; i--)
         {
             if (this._keyComparer.Equals(name, this.BaseGetKey(i)))
             {
                 this._entriesArray.RemoveAt(i);
             }
         }
     }
     else
     {
         this._nullKeyEntry = null;
         for (int j = this._entriesArray.Count - 1; j >= 0; j--)
         {
             if (this.BaseGetKey(j) == null)
             {
                 this._entriesArray.RemoveAt(j);
             }
         }
     }
     this._version++;
 }