-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSafeDictionary.cs
65 lines (50 loc) · 1.01 KB
/
SafeDictionary.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
namespace GodLesZ.Library {
public class SafeDictionary<TKey, TValue> : Dictionary<TKey, TValue> {
private Object mLock = new Object();
public new ValueCollection Values {
get {
lock (mLock) {
return base.Values;
}
}
}
public new KeyCollection Keys {
get {
lock (mLock) {
return base.Keys;
}
}
}
public SafeDictionary()
: base() {
}
public SafeDictionary(int cap)
: base(cap) {
}
public SafeDictionary(IDictionary<TKey, TValue> dictionary)
: base(dictionary) {
}
new public void Add(TKey key, TValue value) {
lock (mLock) {
base.Add(key, value);
}
}
new public bool Remove(TKey key) {
lock (mLock) {
return base.Remove(key);
}
}
public void CopyValuesTo(TValue[] array, int index) {
lock (mLock) {
base.Values.CopyTo(array, index);
}
}
public void CopyKeysTo(TKey[] array, int index) {
lock (mLock) {
base.Keys.CopyTo(array, index);
}
}
}
}