SafeDictionary.cs 759 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace CP.Common.fastJSON
  6. {
  7. public class SafeDictionary<TKey, TValue>
  8. {
  9. private readonly object _Padlock = new object();
  10. private readonly Dictionary<TKey, TValue> _Dictionary = new Dictionary<TKey, TValue>();
  11. public bool ContainsKey(TKey key)
  12. {
  13. return _Dictionary.ContainsKey(key);
  14. }
  15. public TValue this[TKey key]
  16. {
  17. get
  18. {
  19. return _Dictionary[key];
  20. }
  21. }
  22. public void Add(TKey key, TValue value)
  23. {
  24. lock (_Padlock)
  25. {
  26. _Dictionary.Add(key, value);
  27. }
  28. }
  29. }
  30. }