DictionaryExtensions.cs 535 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public static class DictionaryExtensions
  4. {
  5. /// <summary>
  6. /// When DEBUG compiler directive is enabled, we will have more meaningful logs if the key doesn't exist
  7. /// </summary>
  8. public static L GetValueForKey<T, L>(
  9. this Dictionary<T,L> dict, T key)
  10. {
  11. #if DEBUG
  12. if (dict.ContainsKey(key))
  13. {
  14. return dict[key];
  15. } else
  16. {
  17. AVDebug.LogError("Key "+key+ " was not found in dictionary");
  18. return default(L);
  19. }
  20. #else
  21. return dict[key];
  22. #endif
  23. }
  24. }