You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
990 B
C#

10 months ago
using System;
using System.Collections.Generic;
namespace JsonHelper
{
internal class SafeDictionary<TKey, TValue>
{
private readonly object _Padlock = new object();
private readonly Dictionary<TKey, TValue> _Dictionary = new Dictionary<TKey, TValue>();
public bool TryGetValue(TKey key, out TValue value)
{
return _Dictionary.TryGetValue(key, out value);
}
public TValue this[TKey key]
{
get
{
return _Dictionary[key];
}
}
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return ((ICollection<KeyValuePair<TKey, TValue>>)_Dictionary).GetEnumerator();
}
public void Add(TKey key, TValue value)
{
lock (_Padlock)
{
if (_Dictionary.ContainsKey(key) == false)
_Dictionary.Add(key, value);
}
}
}
}