using System.Collections.Generic; namespace GameKit.Dependencies.Utilities { public static class DictionaryFN { /// /// Uses a hacky way to TryGetValue on a dictionary when using IL2CPP and on mobile. /// This is to support older devices that don't properly handle IL2CPP builds. /// public static bool TryGetValueIL2CPP(this IReadOnlyDictionary dict, TKey key, out TValue value) { #if ENABLE_IL2CPP && UNITY_IOS || UNITY_ANDROID if (dict.ContainsKey(key)) { value = dict[key]; return true; } value = default; return false; #else return dict.TryGetValue(key, out value); #endif } /// /// Returns values as a list. /// /// public static List ValuesToList(this IReadOnlyDictionary dict, bool useCache) { List result = useCache ? CollectionCaches.RetrieveList() : new(dict.Count); //No need to clear the list since it's already clear. dict.ValuesToList(ref result, clearLst: false); return result; } /// /// Adds values to a list. /// public static void ValuesToList(this IReadOnlyDictionary dict, ref List result, bool clearLst) { if (clearLst) result.Clear(); foreach (TValue item in dict.Values) result.Add(item); } /// /// Returns keys as a list. /// public static List KeysToList(this IReadOnlyDictionary dict, bool useCache) { List result = useCache ? CollectionCaches.RetrieveList() : new(dict.Count); //No need to clear the list since it's already clear. dict.KeysToList(ref result, clearLst: false); return result; } /// /// Adds keys to a list. /// public static void KeysToList(this IReadOnlyDictionary dict, ref List result, bool clearLst) { result.Clear(); foreach (TKey item in dict.Keys) result.Add(item); } } }