/// <summary> /// Either add a new item, or if it already exists, update it. /// </summary> /// <typeparam name="T">Key type.</typeparam> /// <typeparam name="J">Value type.</typeparam> /// <param name="source">The source.</param> /// <param name="prop">The property.</param> /// <returns>IDictionary<T, J>.</returns> public static IDictionary <T, J> AddOrUpdate <T, J>(this IDictionary <T, J> source, KeyValuePair <T, J> prop) { if (!source.TryAdd(prop.Key, prop.Value)) { source[prop.Key] = prop.Value; } return(source); }
/// <summary> /// Either add a new item, or if it already exists, update it. /// </summary> /// <typeparam name="T">Key type.</typeparam> /// <typeparam name="J">Value type.</typeparam> /// <param name="source">The source.</param> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <returns>IDictionary<T, J>.</returns> public static IDictionary <T, J> AddOrUpdate <T, J>(this IDictionary <T, J> source, T key, J value) { if (!source.TryAdd(key, value)) { source[key] = value; } return(source); }