Ejemplo n.º 1
0
    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;
        }
    }
Ejemplo n.º 2
0
 public bool Remove(XmlDictionaryEntry <TKey, TValue> item)
 {
     return(this.Dictionary.Remove(item.Key));
 }
Ejemplo n.º 3
0
 public void Add(XmlDictionaryEntry <TKey, TValue> item)
 {
     this.Dictionary.Add(item.Key, item.Value);
 }
Ejemplo n.º 4
0
 public bool Contains(XmlDictionaryEntry <TKey, TValue> item)
 {
     return(this.Dictionary.ContainsKey(item.Key));
 }
Ejemplo n.º 5
0
        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>();
        }