public void CopyTo(XmlDictionaryEntry <TKey, TValue>[] array, int arrayIndex) { int index = arrayIndex; if (arrayIndex + this.Dictionary.Count > array.Length) { throw new ArgumentException(ExceptionMessages.CopyToNotEnoughSpace); } foreach (var kvp in this.Dictionary) { var entry = new XmlDictionaryEntry <TKey, TValue> { Key = kvp.Key, Value = kvp.Value }; array[index++] = entry; } }
public bool Remove(XmlDictionaryEntry <TKey, TValue> item) { return(this.Dictionary.Remove(item.Key)); }
public void Add(XmlDictionaryEntry <TKey, TValue> item) { this.Dictionary.Add(item.Key, item.Value); }
public bool Contains(XmlDictionaryEntry <TKey, TValue> item) { return(this.Dictionary.ContainsKey(item.Key)); }
public void ShouldRejectDuplicateKeys() { var dictionary = new XmlDictionary { {"key1", "value1"}, {"key2", "value2"} }; // Check for duplicate keys when adding new entries dictionary.Invoking(x => x.Add("key1", "newValue1")).ShouldThrow<ArgumentException>(); // Check for duplicate keys when modifying existing entries var entry = new XmlDictionaryEntry("key3", "value3"); dictionary.Add(entry); entry.Invoking(x => x.Key = "key1").ShouldThrow<InvalidOperationException>(); }