| 1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MECF.Framework.Common.Extens
- {
- public static class DictionaryExtensions
- {
- public static void TryAddValue<TKey, TValue>(this Dictionary<TKey, List<TValue>> dictionary, TKey key, TValue value, bool isReplace = true)
- {
- if (dictionary.ContainsKey(key))
- {
- dictionary[key].Add(value);
- }
- else
- {
- dictionary.Add(key, new List<TValue> { value });
- }
- }
- public static void TryAddValue<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value, bool isReplace = true)
- {
- if (dictionary.ContainsKey(key))
- {
- if (isReplace)
- dictionary[key] = value;
- }
- else
- {
- dictionary.Add(key, value);
- }
- }
- }
- }
|