using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace Indy.IL2CPU { public class ReadOnlyDictionary : IDictionary { private readonly IDictionary mBackend; public ReadOnlyDictionary(IDictionary aBackend) { mBackend = aBackend; } /// /// Returns an enumerator that iterates through the collection. /// /// /// A that can be used to iterate through the collection. /// /// 1 public IEnumerator> GetEnumerator() { return mBackend.GetEnumerator(); } /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to iterate through the collection. /// /// 2 IEnumerator IEnumerable.GetEnumerator() { return mBackend.GetEnumerator(); } /// /// Adds an item to the . /// /// The object to add to the . /// The is read-only. public void Add(KeyValuePair item) { throw new InvalidOperationException("Cannot add to a read-only Dictionary!"); } /// /// Removes all items from the . /// /// The is read-only. public void Clear() { throw new InvalidOperationException("Cannot clear a read-only Dictionary"); } /// /// Determines whether the contains a specific value. /// /// /// true if is found in the ; otherwise, false. /// /// The object to locate in the . public bool Contains(KeyValuePair item) { return mBackend.Contains(item); } /// /// Copies the elements of the to an , starting at a particular index. /// /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. /// The zero-based index in at which copying begins. /// is null. /// is less than 0. /// is multidimensional.-or- is equal to or greater than the length of .-or-The number of elements in the source is greater than the available space from to the end of the destination .-or-Type cannot be cast automatically to the type of the destination . public void CopyTo(KeyValuePair[] array, int arrayIndex) { mBackend.CopyTo(array, arrayIndex); } /// /// Removes the first occurrence of a specific object from the . /// /// /// true if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . /// /// The object to remove from the . /// The is read-only. public bool Remove(KeyValuePair item) { throw new InvalidOperationException("Cannot remove from a read-only Dictionary"); } /// /// Gets the number of elements contained in the . /// /// /// The number of elements contained in the . /// public int Count { get { return mBackend.Count; } } /// /// Gets a value indicating whether the is read-only. /// /// /// true if the is read-only; otherwise, false. /// public bool IsReadOnly { get { return true; } } /// /// Determines whether the contains an element with the specified key. /// /// /// true if the contains an element with the key; otherwise, false. /// /// The key to locate in the . /// is null. public bool ContainsKey(K key) { return mBackend.ContainsKey(key); } /// /// Adds an element with the provided key and value to the . /// /// The object to use as the key of the element to add. /// The object to use as the value of the element to add. /// is null. /// An element with the same key already exists in the . /// The is read-only. public void Add(K key, V value) { throw new InvalidOperationException("Cannot add to a read-only Dictionary"); } /// /// Removes the element with the specified key from the . /// /// /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . /// /// The key of the element to remove. /// is null. /// The is read-only. public bool Remove(K key) { throw new InvalidOperationException("Cannot remove from a read-only Dictionary"); } /// /// Gets the value associated with the specified key. /// /// /// true if the object that implements contains an element with the specified key; otherwise, false. /// /// The key whose value to get. /// When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. /// is null. public bool TryGetValue(K key, out V value) { return mBackend.TryGetValue(key, out value); } /// /// Gets or sets the element with the specified key. /// /// /// The element with the specified key. /// /// The key of the element to get or set. /// is null. /// The property is retrieved and is not found. /// The property is set and the is read-only. public V this[K key] { get { return mBackend[key]; } set { throw new InvalidOperationException("Cannot change elements in a read-only Dictionary"); } } /// /// Gets an containing the keys of the . /// /// /// An containing the keys of the object that implements . /// public ICollection Keys { get { return mBackend.Keys; } } /// /// Gets an containing the values in the . /// /// /// An containing the values in the object that implements . /// public ICollection Values { get { return mBackend.Values; } } } }