Humility/Query/HUMQuery_Root.cs
/// <summary>
/// Defines new keys in a dictionary if it does not exist.
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="dictionary"></param>
/// <param name="deserializedDictionary"></param>
/// <param name="key"></param>
/// <param name="onCreated"></param>
/// <param name="onAdded"></param>
/// <returns></returns>
Defines new keys in a dictionary if it does not exist.
Defines new keys in a dictionary if it does not exist .
public static TValue Define<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Dictionary<TKey, TValue> deserializedDictionary, TKey key, Func<TValue, TValue> onCreated, Action<TValue> exists)
        {
            TValue value = (TValue)typeof(TValue).Default();
            if (!deserializedDictionary.ContainsKey(key))
            {
                value = onCreated(value);
            }
            else
            {
                value = deserializedDictionary[key];
                dictionary.Add(key, value);
                exists?.DynamicInvoke(value);
            }
            return value; 
        }
public static TValue Define < TKey , TValue > ( this Dictionary < TKey , TValue > dictionary , Dictionary < TKey , TValue > deserializedDictionary , TKey key , Func < TValue , TValue > onCreated , Action < TValue > exists ) { TValue value = ( TValue ) typeof ( TValue ) . Default ( ) ; if ( ! deserializedDictionary . ContainsKey ( key ) ) { value = onCreated ( value ) ; } else { value = deserializedDictionary [ key ] ; dictionary . Add ( key , value ) ; exists ? . DynamicInvoke ( value ) ; } return value ; }
Defines new keys in a dictionary if it does not exist.
Defines new keys in a dictionary if it does not exist .
None
Dictionary<TKey, TValue>
this
deserializedDictionary
Dictionary<TKey, TValue>
None
key
TKey
None
onCreated
Func<TValue, TValue>
None
exists
Action<TValue>
dictionary
None
onAdded
None
typeparam
None
typeparam
None