暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EnumerableExtensions.cs 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace UnityEngine.Purchasing
  5. {
  6. static class EnumerableExtensions
  7. {
  8. public static IEnumerable<T> NonNull<T>(this IEnumerable<T> enumerable)
  9. {
  10. return enumerable.Where(obj => obj != null);
  11. }
  12. public static IEnumerable<T> IgnoreExceptions<T, TException>(this IEnumerable<T> enumerable,
  13. Action<TException> onException = null) where TException : Exception
  14. {
  15. using var enumerator = enumerable.GetEnumerator();
  16. var hasNext = true;
  17. while (hasNext)
  18. {
  19. try
  20. {
  21. hasNext = enumerator.MoveNext();
  22. }
  23. catch (TException ex)
  24. {
  25. onException?.Invoke(ex);
  26. continue;
  27. }
  28. if (hasNext)
  29. {
  30. yield return enumerator.Current;
  31. }
  32. }
  33. }
  34. }
  35. }