/// <summary>Removes the entries with the specified key from the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="name">The <see cref="T:System.String" /> key of the entries to remove. The key can be null.</param> /// <exception cref="T:System.NotSupportedException">The collection is read-only. </exception> protected void BaseRemove(string name) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } if (name != null) { this.m_ItemsContainer.Remove(name); } else { this.m_NullKeyItem = null; } int num = this.m_ItemsArray.Count; int i = 0; while (i < num) { string s = this.BaseGetKey(i); if (this.Equals(s, name)) { this.m_ItemsArray.RemoveAt(i); num--; } else { i++; } } }
/// <summary>Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and returns the data needed to serialize the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object that contains the information required to serialize the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</param> /// <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> object that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="info" /> is null.</exception> public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } int count = this.Count; string[] array = new string[count]; object[] array2 = new object[count]; int num = 0; foreach (object obj in this.m_ItemsArray) { NameObjectCollectionBase._Item item = (NameObjectCollectionBase._Item)obj; array[num] = item.key; array2[num] = item.value; num++; } if (this.equality_comparer != null) { info.AddValue("KeyComparer", this.equality_comparer, typeof(IEqualityComparer)); info.AddValue("Version", 4, typeof(int)); } else { info.AddValue("HashProvider", this.m_hashprovider, typeof(IHashCodeProvider)); info.AddValue("Comparer", this.m_comparer, typeof(IComparer)); info.AddValue("Version", 2, typeof(int)); } info.AddValue("ReadOnly", this.m_readonly); info.AddValue("Count", count); info.AddValue("Keys", array, typeof(string[])); info.AddValue("Values", array2, typeof(object[])); }
/// <summary>Sets the value of the entry at the specified index of the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="index">The zero-based index of the entry to set.</param> /// <param name="value">The <see cref="T:System.Object" /> that represents the new value of the entry to set. The value can be null.</param> /// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> is outside the valid range of indexes for the collection.</exception> protected void BaseSet(int index, object value) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } NameObjectCollectionBase._Item item = (NameObjectCollectionBase._Item) this.m_ItemsArray[index]; item.value = value; }
/// <summary>Gets the value of the first entry with the specified key from the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <returns>An <see cref="T:System.Object" /> that represents the value of the first entry with the specified key, if found; otherwise, null.</returns> /// <param name="name">The <see cref="T:System.String" /> key of the entry to get. The key can be null.</param> protected object BaseGet(string name) { NameObjectCollectionBase._Item item = this.FindFirstMatchedItem(name); if (item == null) { return(null); } return(item.value); }
private void Init() { if (this.equality_comparer != null) { this.m_ItemsContainer = new Hashtable(this.m_defCapacity, this.equality_comparer); } else { this.m_ItemsContainer = new Hashtable(this.m_defCapacity, this.m_hashprovider, this.m_comparer); } this.m_ItemsArray = new ArrayList(); this.m_NullKeyItem = null; }
/// <summary>Sets the value of the first entry with the specified key in the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance, if found; otherwise, adds an entry with the specified key and value into the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="name">The <see cref="T:System.String" /> key of the entry to set. The key can be null.</param> /// <param name="value">The <see cref="T:System.Object" /> that represents the new value of the entry to set. The value can be null.</param> /// <exception cref="T:System.NotSupportedException">The collection is read-only. </exception> protected void BaseSet(string name, object value) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } NameObjectCollectionBase._Item item = this.FindFirstMatchedItem(name); if (item != null) { item.value = value; } else { this.BaseAdd(name, value); } }
/// <summary>Removes the entry at the specified index of the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="index">The zero-based index of the entry to remove.</param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> is outside the valid range of indexes for the collection.</exception> /// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception> protected void BaseRemoveAt(int index) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } string text = this.BaseGetKey(index); if (text != null) { this.m_ItemsContainer.Remove(text); } else { this.m_NullKeyItem = null; } this.m_ItemsArray.RemoveAt(index); }
/// <summary>Adds an entry with the specified key and value into the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary> /// <param name="name">The <see cref="T:System.String" /> key of the entry to add. The key can be null.</param> /// <param name="value">The <see cref="T:System.Object" /> value of the entry to add. The value can be null.</param> /// <exception cref="T:System.NotSupportedException">The collection is read-only. </exception> protected void BaseAdd(string name, object value) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } NameObjectCollectionBase._Item item = new NameObjectCollectionBase._Item(name, value); if (name == null) { if (this.m_NullKeyItem == null) { this.m_NullKeyItem = item; } } else if (this.m_ItemsContainer[name] == null) { this.m_ItemsContainer.Add(name, item); } this.m_ItemsArray.Add(item); }