90 lines
2.1 KiB
C#
90 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using JD.Collections.Interfaces;
|
|
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace JD.Collections.ObjectModel
|
|
{
|
|
public class ReadOnlyKeyedCollection<TKey, TValue> : ReadOnlyCollectionBase<TValue>, IKeyedCollection<TKey, TValue>
|
|
{
|
|
#region Variables
|
|
|
|
private readonly KeyedCollection<TKey, TValue> m_wrappedCollection;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="collection"></param>
|
|
public ReadOnlyKeyedCollection(KeyedCollection<TKey, TValue> collection)
|
|
{
|
|
Throw.IfNull(collection, "collection");
|
|
m_wrappedCollection = collection;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Count.
|
|
/// </summary>
|
|
public override int Count
|
|
{
|
|
get { return m_wrappedCollection.Count; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indexer.
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public TValue this[TKey key]
|
|
{
|
|
get { return m_wrappedCollection[key]; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// ContainsKey.
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public bool ContainsKey(TKey key)
|
|
{
|
|
return m_wrappedCollection.ContainsKey(key);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove.
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public bool Remove(TKey key)
|
|
{
|
|
MethodModifiesCollection();
|
|
return false;
|
|
}
|
|
|
|
public bool TryGetValue(TKey key, out TValue value)
|
|
{
|
|
return m_wrappedCollection.TryGetValue(key, out value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetEnumerator.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override IEnumerator<TValue> GetEnumerator()
|
|
{
|
|
return m_wrappedCollection.GetEnumerator();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|