프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / Standard Assets / ThreadSafeDictionary.cs @ 9

이력 | 보기 | 이력해설 | 다운로드 (1.35 KB)

1
#if !(UNITY_WSA_10_0 && NETFX_CORE)
2
using System;
3
using System.Collections.Generic;
4
using System.Runtime.InteropServices;
5
using System.Linq;
6

    
7
namespace Helper
8
{
9
    public class ThreadSafeDictionary<TKey, TValue>
10
    {
11
        protected readonly Dictionary<TKey, TValue> _impl = new Dictionary<TKey, TValue>();
12
        public TValue this[TKey key]
13
        {
14
            get
15
            {
16
                lock (_impl)
17
                {
18
                    return _impl[key];
19
                }
20
            }
21
            set
22
            {
23
                lock (_impl)
24
                {
25
                    _impl[key] = value;
26
                }
27
            }
28
        }
29

    
30
        public void Add(TKey key, TValue value)
31
        {
32
            lock (_impl)
33
            {
34
                _impl.Add(key, value);
35
            }
36
        }
37

    
38
        public bool TryGetValue(TKey key, out TValue value)
39
        {
40
            lock (_impl)
41
            {
42
                return _impl.TryGetValue(key, out value);
43
            }
44
        }
45

    
46
        public bool Remove(TKey key)
47
        {
48
            lock (_impl)
49
            {
50
                return _impl.Remove(key);
51
            }
52
        }
53

    
54
        public void Clear()
55
        {
56
            lock (_impl)
57
            {
58
                _impl.Clear();
59
            }
60
        }
61
    }
62
}
63
#endif