-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from kluhman/preview-support
Preview support
- Loading branch information
Showing
7 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace UmbracoVault.Extensions | ||
{ | ||
internal static class DictionaryExtensions | ||
{ | ||
public static object GetOrAddThreadSafe(this IDictionary dictionary, object key, Func<object, object> valueFactory) | ||
{ | ||
if (!dictionary.Contains(key)) | ||
{ | ||
lock (key) | ||
{ | ||
if (!dictionary.Contains(key)) | ||
{ | ||
dictionary.Add(key, valueFactory(key)); | ||
} | ||
} | ||
} | ||
|
||
return dictionary[key]; | ||
} | ||
|
||
public static object GetOrAddThreadSafe(this IDictionary dictionary, object key, object value) | ||
{ | ||
return dictionary.GetOrAddThreadSafe(key, k => value); | ||
} | ||
|
||
public static T GetOrAddThreadSafe<T>(this IDictionary dictionary, object key, Func<object, T> valueFactory) | ||
{ | ||
var factoryWrapper = new Func<object, object>(k => valueFactory(k)); | ||
return (T)dictionary.GetOrAddThreadSafe(key, factoryWrapper); | ||
} | ||
|
||
public static T GetOrAddThreadSafe<T>(this IDictionary dictionary, object key, T value) | ||
{ | ||
return dictionary.GetOrAddThreadSafe(key, k => value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters