using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BuzzGUI.Interfaces { public class ReadOnlyDictionary : IDictionary { IDictionary d; public IDictionary Dictionary { get { return d; } } public ReadOnlyDictionary(IDictionary d) { this.d = d; } #region IDictionary Members public bool ContainsKey(K key) { return d.ContainsKey(key); } public ICollection Keys { get { return d.Keys; } } public bool TryGetValue(K key, out V value) { return d.TryGetValue(key, out value); } public ICollection Values { get { return d.Values; } } public V this[K key] { get { return d[key]; } set { throw new NotSupportedException(); } } public void Add(K key, V value) { throw new NotSupportedException(); } public bool Remove(K key) { throw new NotSupportedException(); } #endregion #region ICollection> Members public bool Contains(KeyValuePair item) { return d.Contains(item); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { d.CopyTo(array, arrayIndex); } public int Count { get { return d.Count; } } public bool IsReadOnly { get { return true; } } public void Add(KeyValuePair item) { throw new NotSupportedException(); } public void Clear() { throw new NotSupportedException(); } public bool Remove(KeyValuePair item) { throw new NotSupportedException(); } #endregion #region IEnumerable> Members public IEnumerator> GetEnumerator() { return d.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return d.GetEnumerator(); } #endregion } public static class IDictionaryExtensions { public static ReadOnlyDictionary AsReadOnly(this IDictionary d) { return new ReadOnlyDictionary(d); } } }