Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SnowMaker
- {
- static class DictionaryExtensions
- {
- internal static TValue GetValue<TKey, TValue>(
- this IDictionary<TKey, TValue> dictionary,
- TKey key,
- object dictionaryLock,
- Func<TValue> valueInitializer)
- {
- TValue value;
- var found = dictionary.TryGetValue(key, out value);
- if (found) return value;
- lock (dictionaryLock)
- {
- found = dictionary.TryGetValue(key, out value);
- if (found) return value;
- value = valueInitializer();
- dictionary.Add(key, value);
- }
- return value;
- }
- }
- }
Add Comment
Please, Sign In to add comment