// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; using System; using System.Collections.Generic; using System.Linq; namespace PixelCrushers { /// /// Extension methods for generic dictionaries. /// public static class DictionaryExtensions { /// /// Works like List.RemoveAll. /// /// Key type /// Value type /// Dictionary to remove entries from /// Delegate to match keys /// Number of entries removed public static int RemoveAll(this IDictionary dictionary, Predicate match) { if (dictionary == null || match == null) return 0; var keysToRemove = dictionary.Keys.Where(k => match(k)).ToList(); if (keysToRemove.Count > 0) { foreach (var key in keysToRemove) { dictionary.Remove(key); } } return keysToRemove.Count; } } }