I found this Extension for C# to convert GetOrAdd to Lazy and I want to do the same for AddOrUpdate.
Can someone help me convert this to AddOrUpdate?
public static class ConcurrentDictionaryExtensions
{
public static TValue LazyGetOrAdd<TKey, TValue>(
this ConcurrentDictionary<TKey, Lazy<TValue>> dictionary,
TKey key,
Func<TKey, TValue> valueFactory)
{
if (dictionary == null) throw new ArgumentNullException("dictionary");
var result = dictionary.GetOrAdd(key, new Lazy<TValue>(() => valueFactory(key)));
return result.Value;
}
}