BusterWood.Caching/DictionaryExtensions.cs
/// <summary>
/// Tries to get a value from <paramref name="dictionary"/>.  Returns TRUE if the value was already in the <paramref name="dictionary"/>,
/// otherwise creates the <paramref name="value"/> using <paramref name="valueFactory"/>, adds it to the <paramref name="dictionary"/> and returns FALSE.
/// </summary>
Tries to get a value from .  Returns TRUE if the value was already in the ,
otherwise creates the  using , adds it to the  and returns FALSE.
Tries to get a value from . Returns TRUE if the value was already in the otherwise creates the using adds it to the and returns FALSE .
public static bool TryGetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory, out TValue value)
        {
            if (dictionary.TryGetValue(key, out value))
            {
                return true;
            }
            else
            {
                value = valueFactory(key);
                dictionary.Add(key, value);
                return false;
            }
        }
public static bool TryGetOrAdd < TKey , TValue > ( this Dictionary < TKey , TValue > dictionary , TKey key , Func < TKey , TValue > valueFactory , out TValue value ) { if ( dictionary . TryGetValue ( key , out value ) ) { return true ; } else { value = valueFactory ( key ) ; dictionary . Add ( key , value ) ; return false ; } }
Tries to get a value from .
Tries to get a value from .
Dictionary<TKey, TValue>
this
key
TKey
valueFactory
Func<TKey, TValue>
TValue
out