Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MiscHelpers.cs 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections.Generic;
  2. namespace UnityEngine.InputSystem.Utilities
  3. {
  4. internal static class MiscHelpers
  5. {
  6. public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
  7. {
  8. return dictionary.TryGetValue(key, out var value) ? value : default;
  9. }
  10. public static IEnumerable<TValue> EveryNth<TValue>(this IEnumerable<TValue> enumerable, int n, int start = 0)
  11. {
  12. var index = 0;
  13. foreach (var element in enumerable)
  14. {
  15. if (index < start)
  16. {
  17. ++index;
  18. continue;
  19. }
  20. if ((index - start) % n == 0)
  21. yield return element;
  22. ++index;
  23. }
  24. }
  25. public static int IndexOf<TValue>(this IEnumerable<TValue> enumerable, TValue value)
  26. {
  27. var index = 0;
  28. foreach (var element in enumerable)
  29. if (EqualityComparer<TValue>.Default.Equals(element, value))
  30. return index;
  31. else
  32. ++index;
  33. return -1;
  34. }
  35. }
  36. }