//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections.Generic;
///
/// Represents a read-only dictionary.
///
/// The type of the key.
/// The type of the value.
internal class ReadOnlyDictionary : IDictionary {
///
/// Contains base dictionary.
///
private readonly IDictionary baseDictionary;
///
/// Initializes a new instance of the class.
///
/// The base dictionary.
public ReadOnlyDictionary(IDictionary baseDictionary) {
this.baseDictionary = baseDictionary;
}
///
/// Gets an containing the keys of the .
///
///
/// An containing the keys of the object that implements .
///
public ICollection Keys {
get { return this.baseDictionary.Keys; }
}
///
/// Gets an containing the values in the .
///
///
/// An containing the values in the object that implements .
///
public ICollection Values {
get { return this.baseDictionary.Values; }
}
///
/// Gets the number of elements contained in the .
///
///
/// The number of elements contained in the .
///
public int Count {
get { return this.baseDictionary.Count; }
}
///
/// Gets a value indicating whether the is read-only.
///
/// true if the is read-only; otherwise, false.
///
public bool IsReadOnly {
get { return true; }
}
///
/// Gets or sets the element with the specified key.
///
/// The key being read or written.
///
/// The element with the specified key.
///
/// 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 this.baseDictionary[key]; }
set { throw new NotSupportedException(); }
}
///
/// 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 NotSupportedException();
}
///
/// Determines whether the contains an element with the specified key.
///
/// The key to locate in the .
///
/// true if the contains an element with the key; otherwise, false.
///
/// is null.
///
public bool ContainsKey(K key) {
return this.baseDictionary.ContainsKey(key);
}
///
/// Removes the element with the specified key from the .
///
/// The key of the element to remove.
///
/// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original .
///
/// is null.
///
///
/// The is read-only.
///
public bool Remove(K key) {
throw new NotSupportedException();
}
///
/// Gets the value associated with the specified key.
///
/// 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.
///
/// true if the object that implements contains an element with the specified key; otherwise, false.
///
/// is null.
///
public bool TryGetValue(K key, out V value) {
return this.baseDictionary.TryGetValue(key, out value);
}
///
/// Adds an item to the .
///
/// The object to add to the .
///
/// The is read-only.
///
public void Add(KeyValuePair item) {
throw new NotSupportedException();
}
///
/// Removes all items from the .
///
///
/// The is read-only.
///
public void Clear() {
throw new NotSupportedException();
}
///
/// Determines whether the contains a specific value.
///
/// The object to locate in the .
///
/// true if is found in the ; otherwise, false.
///
public bool Contains(KeyValuePair item) {
return this.baseDictionary.Contains(item);
}
///
/// Copies to.
///
/// The array.
/// Index of the array.
public void CopyTo(KeyValuePair[] array, int arrayIndex) {
this.baseDictionary.CopyTo(array, arrayIndex);
}
///
/// Removes the first occurrence of a specific object from the .
///
/// The object to remove from the .
///
/// true if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original .
///
///
/// The is read-only.
///
public bool Remove(KeyValuePair item) {
throw new NotSupportedException();
}
///
/// Returns an enumerator that iterates through the collection.
///
///
/// A that can be used to iterate through the collection.
///
public IEnumerator> GetEnumerator() {
return this.baseDictionary.GetEnumerator();
}
///
/// Returns an enumerator that iterates through a collection.
///
///
/// An object that can be used to iterate through the collection.
///
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return this.baseDictionary.GetEnumerator();
}
}
}