public static void RemoveFromBaseDictionaryListIfExist <TKey, TListItem>(this BaseDictionary <TKey, List <TListItem> > dictionary, TKey key, TListItem listItem) { if (dictionary.ContainsKey(key)) { var items = dictionary[key]; items.Remove(listItem); } }
public static void ReplaceInBaseDictionaryListIfExist <TKey, TListItem>(this BaseDictionary <TKey, List <TListItem> > dictionary, TKey key, TListItem listItem, TListItem listItemNew) { if (dictionary.ContainsKey(key)) { var items = dictionary[key]; if (items.Contains(listItem)) { var index = items.IndexOf(listItem); items.Remove(listItem); items.Insert(index, listItemNew); } } }
public static void AddToBaseDictionaryListCreateIfNotExist <TKey, TListItem>(this BaseDictionary <TKey, List <TListItem> > dictionary, TKey key, TListItem listItem) { List <TListItem> items; if (dictionary.ContainsKey(key)) { items = dictionary[key]; } else { items = new List <TListItem>(); dictionary.Add(key, items); } if (!items.Contains(listItem)) { items.Add(listItem); } }