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 IDictionary dict, TKey key, out TValue value)
{
#if ENABLE_IL2CPP && UNITY_IOS || UNITY_ANDROID
if (dict.ContainsKey(key))
{
value = dict[key];
return true;
}
else
{
value = default;
return false;
}
#else
return dict.TryGetValue(key, out value);
#endif
}
///
/// Returns values as an allocated list.
///
///
public static List ValuesToList(this IDictionary dict)
{
List result = new(dict.Count);
dict.ValuesToList(ref result);
return result;
}
///
/// Clears a collection and populates it with this dictionaries values.
///
public static void ValuesToList(this IDictionary dict, ref List result)
{
result.Clear();
foreach (TValue item in dict.Values)
result.Add(item);
}
///
/// Clears a collection and populates it with this dictionaries keys.
///
public static void KeysToList(this IDictionary dict, ref List result)
{
result.Clear();
foreach (TKey item in dict.Keys)
result.Add(item);
}
}
}