Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into dev

pull/8242/head
Halil İbrahim Kalkan 6 years ago
parent
commit
65b7c5bf5a
  1. 20
      framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs

20
framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs

@ -67,7 +67,7 @@ namespace System.Collections.Generic
{ {
return dictionary.TryGetValue(key, out var obj) ? obj : default; return dictionary.TryGetValue(key, out var obj) ? obj : default;
} }
/// <summary> /// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find. /// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary> /// </summary>
@ -100,7 +100,7 @@ namespace System.Collections.Generic
return dictionary[key] = factory(key); return dictionary[key] = factory(key);
} }
/// <summary> /// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find. /// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary> /// </summary>
@ -114,5 +114,19 @@ namespace System.Collections.Generic
{ {
return dictionary.GetOrAdd(key, k => factory()); return dictionary.GetOrAdd(key, k => factory());
} }
/// <summary>
/// Gets a value from the concurrent dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Concurrent dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <param name="factory">A factory method used to create the value if not found in the dictionary</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> factory)
{
return dictionary.GetOrAdd(key, k => factory());
}
} }
} }

Loading…
Cancel
Save