1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System.Collections.Generic;
- namespace Amib.Threading.Internal
- {
- internal class SynchronizedDictionary<TKey, TValue>
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
- private readonly object _lock;
- public SynchronizedDictionary()
- {
- _lock = new object();
- _dictionary = new Dictionary<TKey, TValue>();
- }
- public int Count
- {
- get { return _dictionary.Count; }
- }
- public bool Contains(TKey key)
- {
- lock (_lock)
- {
- return _dictionary.ContainsKey(key);
- }
- }
- public void Remove(TKey key)
- {
- lock (_lock)
- {
- _dictionary.Remove(key);
- }
- }
- public object SyncRoot
- {
- get { return _lock; }
- }
- public TValue this[TKey key]
- {
- get
- {
- lock (_lock)
- {
- return _dictionary[key];
- }
- }
- set
- {
- lock (_lock)
- {
- _dictionary[key] = value;
- }
- }
- }
- public Dictionary<TKey, TValue>.KeyCollection Keys
- {
- get
- {
- lock (_lock)
- {
- return _dictionary.Keys;
- }
- }
- }
- public Dictionary<TKey, TValue>.ValueCollection Values
- {
- get
- {
- lock (_lock)
- {
- return _dictionary.Values;
- }
- }
- }
- public void Clear()
- {
- lock (_lock)
- {
- _dictionary.Clear();
- }
- }
- }
- }
|