wasSharp – Diff between revs 39 and 44

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 39 Rev 44
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6 // Based on the work of Herman Schoenfeld 6 // Based on the work of Herman Schoenfeld
7   7  
8 using System.Collections.Generic; 8 using System.Collections.Generic;
9 using System.Linq; 9 using System.Linq;
10 using System.Threading; 10 using System.Threading;
11   11  
12 namespace wasSharp.Collections.Specialized 12 namespace wasSharp.Collections.Specialized
13 { 13 {
14 public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>> 14 public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>>
15 { 15 {
16 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 16 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
17   17  
18 public V this[K1 key1, K2 key2] 18 public V this[K1 key1, K2 key2]
19 { 19 {
20 get 20 get
21 { 21 {
22 SyncRoot.EnterReadLock(); 22 _lock.EnterReadLock();
-   23 try
-   24 {
23 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 25 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
-   26 {
-   27 return default(V);
-   28 }
-   29 return base[key1][key2];
-   30 }
-   31 finally
24 { 32 {
25 SyncRoot.ExitReadLock(); 33 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
26 return default(V); -  
27 } 34 }
28 var v = base[key1][key2]; -  
29 SyncRoot.ExitReadLock(); -  
30 return v; -  
31 } 35 }
32 set 36 set
33 { 37 {
34 SyncRoot.EnterWriteLock(); 38 _lock.EnterWriteLock();
-   39 try
-   40 {
35 if (!ContainsKey(key1)) 41 if (!ContainsKey(key1))
36 this[key1] = new Dictionary<K2, V>(); 42 this[key1] = new Dictionary<K2, V>();
37   43  
-   44 this[key1][key2] = value;
-   45 }
-   46 finally
38 this[key1][key2] = value; 47 {
-   48 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
39 SyncRoot.ExitWriteLock(); 49 }
40 } 50 }
41 } 51 }
42   52  
43 public new IEnumerable<V> Values 53 public new IEnumerable<V> Values
44 { 54 {
45 get 55 get
46 { 56 {
47 SyncRoot.EnterReadLock(); 57 _lock.EnterReadLock();
-   58 try
-   59 {
48 var v = base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]); 60 return base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]);
-   61 }
-   62 finally
-   63 {
49 SyncRoot.ExitReadLock(); 64 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
50 return v; 65 }
51 } 66 }
52 } 67 }
53   68  
54 public void Add(K1 key1, K2 key2, V value) 69 public void Add(K1 key1, K2 key2, V value)
55 { 70 {
56 SyncRoot.EnterWriteLock(); 71 _lock.EnterWriteLock();
-   72 try
-   73 {
57 if (!ContainsKey(key1)) 74 if (!ContainsKey(key1))
58 this[key1] = new Dictionary<K2, V>(); 75 this[key1] = new Dictionary<K2, V>();
59   76  
-   77 this[key1][key2] = value;
-   78 }
-   79 finally
60 this[key1][key2] = value; 80 {
-   81 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
61 SyncRoot.ExitWriteLock(); 82 }
62 } 83 }
63   84  
64 public void Remove(K1 key1, K2 key2) 85 public void Remove(K1 key1, K2 key2)
65 { 86 {
66 SyncRoot.EnterWriteLock(); 87 _lock.EnterWriteLock();
67 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 88 try
68 { 89 {
-   90 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
-   91 {
-   92 return;
-   93 }
69 SyncRoot.ExitWriteLock(); 94 this[key1].Remove(key2);
70 return; 95 Remove(key1);
-   96 }
-   97 finally
-   98 {
-   99 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
71 } 100 }
72 this[key1].Remove(key2); -  
73 Remove(key1); -  
74 SyncRoot.ExitWriteLock(); -  
75 } 101 }
76   102  
77 public bool ContainsKey(K1 key1, K2 key2) 103 public bool ContainsKey(K1 key1, K2 key2)
78 { 104 {
79 SyncRoot.EnterReadLock(); 105 _lock.EnterReadLock();
-   106 try
-   107 {
80 var c = ContainsKey(key1) && this[key1].ContainsKey(key2); 108 return ContainsKey(key1) && this[key1].ContainsKey(key2);
-   109 }
-   110 finally
-   111 {
81 SyncRoot.ExitReadLock(); 112 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
82 return c; 113 }
83 } 114 }
84   115  
85 public bool TryGetValue(K1 key1, K2 key2, out V value) 116 public bool TryGetValue(K1 key1, K2 key2, out V value)
86 { 117 {
87 SyncRoot.EnterReadLock(); 118 _lock.EnterReadLock();
88 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 119 try
89 { 120 {
-   121 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
90 SyncRoot.ExitReadLock(); 122 {
91 value = default(V); 123 value = default(V);
92 return false; 124 return false;
93 } 125 }
94 value = base[key1][key2]; 126 value = base[key1][key2];
95 SyncRoot.ExitReadLock(); 127 return true;
-   128 }
96 return true; 129 finally
-   130 {
-   131 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
-   132 }
97 } 133 }
98 } 134 }
99   135  
100 public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>> 136 public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>>
101 { 137 {
102 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 138 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
103   139  
104 public V this[K1 key1, K2 key2, K3 key3] 140 public V this[K1 key1, K2 key2, K3 key3]
105 { 141 {
106 get 142 get
107 { 143 {
108 SyncRoot.EnterReadLock(); 144 _lock.EnterReadLock();
-   145 try
-   146 {
109 var v = ContainsKey(key1) ? this[key1][key2, key3] : default(V); 147 return ContainsKey(key1) ? this[key1][key2, key3] : default(V);
-   148 }
-   149 finally
-   150 {
110 SyncRoot.ExitReadLock(); 151 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
111 return v; 152 }
112 } 153 }
113 set 154 set
114 { 155 {
115 SyncRoot.EnterWriteLock(); 156 _lock.EnterWriteLock();
-   157 try
-   158 {
116 if (!ContainsKey(key1)) 159 if (!ContainsKey(key1))
117 this[key1] = new MultiKeyDictionary<K2, K3, V>(); 160 this[key1] = new MultiKeyDictionary<K2, K3, V>();
-   161  
118 this[key1][key2, key3] = value; 162 this[key1][key2, key3] = value;
-   163 }
-   164 finally
-   165 {
119 SyncRoot.ExitWriteLock(); 166 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   167 }
120 } 168 }
121 } 169 }
122   170  
123 public bool ContainsKey(K1 key1, K2 key2, K3 key3) 171 public bool ContainsKey(K1 key1, K2 key2, K3 key3)
124 { 172 {
125 SyncRoot.EnterReadLock(); 173 _lock.EnterReadLock();
-   174 try
-   175 {
126 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3); 176 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3);
-   177 }
-   178 finally
-   179 {
127 SyncRoot.ExitReadLock(); 180 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
128 return c; 181 }
129 } 182 }
130   183  
131 public void Add(K1 key1, K2 key2, K3 key3, V value) 184 public void Add(K1 key1, K2 key2, K3 key3, V value)
132 { 185 {
133 SyncRoot.EnterWriteLock(); 186 _lock.EnterWriteLock();
-   187 try
-   188 {
134 if (!ContainsKey(key1)) 189 if (!ContainsKey(key1))
135 this[key1] = new MultiKeyDictionary<K2, K3, V>(); 190 this[key1] = new MultiKeyDictionary<K2, K3, V>();
136 this[key1][key2, key3] = value; 191 this[key1][key2, key3] = value;
-   192 }
-   193 finally
-   194 {
137 SyncRoot.ExitWriteLock(); 195 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   196 }
138 } 197 }
139   198  
140 public void Remove(K1 key1, K2 key2, K3 key3) 199 public void Remove(K1 key1, K2 key2, K3 key3)
141 { 200 {
142 SyncRoot.EnterWriteLock(); 201 _lock.EnterWriteLock();
143 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) 202 try
144 { 203 {
-   204 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
-   205 {
-   206 return;
-   207 }
-   208 this[key1][key2].Remove(key3);
145 SyncRoot.ExitWriteLock(); 209 this[key1].Remove(key2);
146 return; 210 Remove(key1);
-   211 }
-   212 finally
-   213 {
-   214 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
147 } 215 }
148 this[key1][key2].Remove(key3); -  
149 this[key1].Remove(key2); -  
150 Remove(key1); -  
151 SyncRoot.ExitWriteLock(); -  
152 } 216 }
153   217  
154 public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value) 218 public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value)
155 { 219 {
156 SyncRoot.EnterReadLock(); 220 _lock.EnterReadLock();
157 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) 221 try
158 { 222 {
-   223 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
159 SyncRoot.ExitReadLock(); 224 {
160 value = default(V); 225 value = default(V);
161 return false; 226 return false;
162 } 227 }
163 value = base[key1][key2, key3]; 228 value = base[key1][key2, key3];
164 SyncRoot.ExitReadLock(); 229 return true;
-   230 }
165 return true; 231 finally
-   232 {
-   233 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
-   234 }
166 } 235 }
167 } 236 }
168   237  
169 public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>> 238 public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>>
170 { 239 {
171 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 240 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
172   241  
173 public V this[K1 key1, K2 key2, K3 key3, K4 key4] 242 public V this[K1 key1, K2 key2, K3 key3, K4 key4]
174 { 243 {
175 get 244 get
176 { 245 {
177 SyncRoot.EnterReadLock(); 246 _lock.EnterReadLock();
-   247 try
-   248 {
178 var v = ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); 249 return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V);
-   250 }
-   251 finally
-   252 {
179 SyncRoot.ExitReadLock(); 253 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
180 return v; 254 }
181 } 255 }
182 set 256 set
183 { 257 {
184 SyncRoot.EnterWriteLock(); 258 _lock.EnterWriteLock();
-   259 try
-   260 {
185 if (!ContainsKey(key1)) 261 if (!ContainsKey(key1))
186 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); 262 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>();
187 this[key1][key2, key3, key4] = value; 263 this[key1][key2, key3, key4] = value;
-   264 }
-   265 finally
-   266 {
188 SyncRoot.ExitWriteLock(); 267 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   268 }
189 } 269 }
190 } 270 }
191   271  
192 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) 272 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4)
193 { 273 {
194 SyncRoot.EnterReadLock(); 274 _lock.EnterReadLock();
-   275 try
-   276 {
195 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); 277 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4);
-   278 }
-   279 finally
-   280 {
196 SyncRoot.ExitReadLock(); 281 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
197 return c; 282 }
198 } 283 }
199 } 284 }
200   285  
201 public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>> 286 public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>>
202 { 287 {
203 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 288 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
204   289  
205 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5] 290 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5]
206 { 291 {
207 get 292 get
208 { 293 {
209 SyncRoot.EnterReadLock(); 294 _lock.EnterReadLock();
-   295 try
-   296 {
210 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); 297 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V);
-   298 }
-   299 finally
-   300 {
211 SyncRoot.ExitReadLock(); 301 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
212 return v; 302 }
213 } 303 }
214 set 304 set
215 { 305 {
216 SyncRoot.EnterWriteLock(); 306 _lock.EnterWriteLock();
-   307 try
-   308 {
217 if (!ContainsKey(key1)) 309 if (!ContainsKey(key1))
218 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); 310 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>();
219 this[key1][key2, key3, key4, key5] = value; 311 this[key1][key2, key3, key4, key5] = value;
-   312 }
-   313 finally
-   314 {
220 SyncRoot.ExitWriteLock(); 315 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   316 }
221 } 317 }
222 } 318 }
223   319  
224 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) 320 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5)
225 { 321 {
226 SyncRoot.EnterReadLock(); 322 _lock.EnterReadLock();
-   323 try
-   324 {
227 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); 325 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5);
-   326 }
-   327 finally
-   328 {
228 SyncRoot.ExitReadLock(); 329 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
229 return c; 330 }
230 } 331 }
231 } 332 }
232   333  
233 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : 334 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> :
234 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> 335 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>>
235 { 336 {
236 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 337 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
237   338  
238 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6] 339 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6]
239 { 340 {
240 get 341 get
241 { 342 {
242 SyncRoot.EnterReadLock(); 343 _lock.EnterReadLock();
-   344 try
-   345 {
243 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); 346 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V);
-   347 }
-   348 finally
-   349 {
244 SyncRoot.ExitReadLock(); 350 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
245 return v; 351 }
246 } 352 }
247 set 353 set
248 { 354 {
249 SyncRoot.EnterWriteLock(); 355 _lock.EnterWriteLock();
-   356 try
-   357 {
250 if (!ContainsKey(key1)) 358 if (!ContainsKey(key1))
251 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); 359 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>();
252 this[key1][key2, key3, key4, key5, key6] = value; 360 this[key1][key2, key3, key4, key5, key6] = value;
-   361 }
-   362 finally
-   363 {
253 SyncRoot.ExitWriteLock(); 364 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   365 }
254 } 366 }
255 } 367 }
256   368  
257 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6) 369 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6)
258 { 370 {
259 SyncRoot.EnterReadLock(); 371 _lock.EnterReadLock();
-   372 try
-   373 {
260 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); 374 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6);
-   375 }
-   376 finally
-   377 {
261 SyncRoot.ExitReadLock(); 378 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
262 return c; 379 }
263 } 380 }
264 } 381 }
265   382  
266 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : 383 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> :
267 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> 384 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>>
268 { 385 {
269 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 386 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
270   387  
271 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7] 388 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7]
272 { 389 {
273 get 390 get
274 { 391 {
275 SyncRoot.EnterReadLock(); 392 _lock.EnterReadLock();
-   393 try
-   394 {
276 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); 395 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V);
-   396 }
-   397 finally
-   398 {
277 SyncRoot.ExitReadLock(); 399 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
278 return v; 400 }
279 } 401 }
280 set 402 set
281 { 403 {
282 SyncRoot.EnterWriteLock(); 404 _lock.EnterWriteLock();
-   405 try
-   406 {
283 if (!ContainsKey(key1)) 407 if (!ContainsKey(key1))
284 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); 408 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>();
285 this[key1][key2, key3, key4, key5, key6, key7] = value; 409 this[key1][key2, key3, key4, key5, key6, key7] = value;
-   410 }
-   411 finally
-   412 {
286 SyncRoot.ExitWriteLock(); 413 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   414 }
287 } 415 }
288 } 416 }
289   417  
290 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7) 418 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7)
291 { 419 {
292 SyncRoot.EnterReadLock(); 420 _lock.EnterReadLock();
-   421 try
-   422 {
293 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); 423 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7);
-   424 }
-   425 finally
-   426 {
294 SyncRoot.ExitReadLock(); 427 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
295 return c; 428 }
296 } 429 }
297 } 430 }
298   431  
299 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> : 432 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> :
300 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> 433 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>>
301 { 434 {
302 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 435 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
303   436  
304 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8] 437 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8]
305 { 438 {
306 get 439 get
307 { 440 {
308 SyncRoot.EnterReadLock(); 441 _lock.EnterReadLock();
-   442 try
-   443 {
309 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); 444 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V);
-   445 }
-   446 finally
-   447 {
310 SyncRoot.ExitReadLock(); 448 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
311 return v; 449 }
312 } 450 }
313 set 451 set
314 { 452 {
315 SyncRoot.EnterWriteLock(); 453 _lock.EnterWriteLock();
-   454 try
-   455 {
316 if (!ContainsKey(key1)) 456 if (!ContainsKey(key1))
317 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>(); 457 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>();
318 this[key1][key2, key3, key4, key5, key6, key7, key8] = value; 458 this[key1][key2, key3, key4, key5, key6, key7, key8] = value;
-   459 }
-   460 finally
-   461 {
319 SyncRoot.ExitWriteLock(); 462 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   463 }
320 } 464 }
321 } 465 }
322   466  
323 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8) 467 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8)
324 { 468 {
325 SyncRoot.EnterReadLock(); 469 _lock.EnterReadLock();
-   470 try
-   471 {
326 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8); 472 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8);
-   473 }
-   474 finally
-   475 {
327 SyncRoot.ExitReadLock(); 476 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
328 return c; 477 }
329 } 478 }
330 } 479 }
331   480  
332 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> : 481 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> :
333 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>> 482 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>>
334 { 483 {
335 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 484 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
336   485  
337 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9] 486 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9]
338 { 487 {
339 get 488 get
340 { 489 {
341 SyncRoot.EnterReadLock(); 490 _lock.EnterReadLock();
-   491 try
-   492 {
342 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); 493 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V);
-   494 }
-   495 finally
-   496 {
343 SyncRoot.ExitReadLock(); 497 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
344 return v; 498 }
345 } 499 }
346 set 500 set
347 { 501 {
348 SyncRoot.EnterWriteLock(); 502 _lock.EnterWriteLock();
-   503 try
-   504 {
349 if (!ContainsKey(key1)) 505 if (!ContainsKey(key1))
350 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>(); 506 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>();
351 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; 507 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value;
-   508 }
-   509 finally
-   510 {
352 SyncRoot.ExitWriteLock(); 511 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   512 }
353 } 513 }
354 } 514 }
355   515  
356 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9) 516 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9)
357 { 517 {
358 SyncRoot.EnterReadLock(); 518 _lock.EnterReadLock();
-   519 try
-   520 {
359 var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9); 521 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9);
-   522 }
-   523 finally
-   524 {
360 SyncRoot.ExitReadLock(); 525 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
361 return c; 526 }
362 } 527 }
363 } 528 }
364   529  
365 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> : 530 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> :
366 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>> 531 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>>
367 { 532 {
368 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 533 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
369   534  
370 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10] 535 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10]
371 { 536 {
372 get 537 get
373 { 538 {
374 SyncRoot.EnterReadLock(); 539 _lock.EnterReadLock();
-   540 try
-   541 {
-   542 return ContainsKey(key1)
375 var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] : default(V); 543 ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10]
376 SyncRoot.ExitReadLock(); 544 : default(V);
-   545 }
377 return v; 546 finally
-   547 {
-   548 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
-   549 }
378 } 550 }
379 set 551 set
380 { 552 {
381 SyncRoot.EnterWriteLock(); 553 _lock.EnterWriteLock();
-   554 try
-   555 {
382 if (!ContainsKey(key1)) 556 if (!ContainsKey(key1))
383 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>(); 557 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>();
384 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value; 558 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value;
-   559 }
-   560 finally
-   561 {
385 SyncRoot.ExitWriteLock(); 562 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   563 }
386 } 564 }
387 } 565 }
388   566  
389 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, 567 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9,
390 K10 key10) 568 K10 key10)
391 { 569 {
392 SyncRoot.EnterReadLock(); 570 _lock.EnterReadLock();
-   571 try
-   572 {
393 var c = ContainsKey(key1) && 573 return ContainsKey(key1) &&
394 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10); 574 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10);
-   575 }
-   576 finally
-   577 {
395 SyncRoot.ExitReadLock(); 578 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
396 return c; 579 }
397 } 580 }
398 } 581 }
399   582  
400 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> : 583 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> :
401 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>> 584 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>>
402 { 585 {
403 private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 586 private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
404   587  
405 public V this[ 588 public V this[
406 K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11] 589 K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11]
407 { 590 {
408 get 591 get
409 { 592 {
410 SyncRoot.EnterReadLock(); 593 _lock.EnterReadLock();
-   594 try
-   595 {
411 var v = ContainsKey(key1) 596 return ContainsKey(key1)
412 ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] 597 ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11]
413 : default(V); 598 : default(V);
-   599 }
-   600 finally
-   601 {
414 SyncRoot.ExitReadLock(); 602 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
415 return v; 603 }
416 } 604 }
417 set 605 set
418 { 606 {
419 SyncRoot.EnterWriteLock(); 607 _lock.EnterWriteLock();
-   608 try
-   609 {
420 if (!ContainsKey(key1)) 610 if (!ContainsKey(key1))
421 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>(); 611 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>();
422 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value; 612 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value;
-   613 }
-   614 finally
-   615 {
423 SyncRoot.ExitWriteLock(); 616 if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
-   617 }
424 } 618 }
425 } 619 }
426   620  
427 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, 621 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9,
428 K10 key10, K11 key11) 622 K10 key10, K11 key11)
429 { 623 {
430 SyncRoot.EnterReadLock(); 624 _lock.EnterReadLock();
-   625 try
-   626 {
431 var c = ContainsKey(key1) && 627 return ContainsKey(key1) &&
432 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11); 628 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11);
-   629 }
-   630 finally
-   631 {
433 SyncRoot.ExitReadLock(); 632 if (_lock.IsReadLockHeld) _lock.ExitReadLock();
434 return c; 633 }
435 } 634 }
436 } 635 }
437 } 636 }
438   637