minesweeper_game/Library/PackageCache/com.unity.purchasing@649c6c7b3b1b/Runtime/Stores/Util/EnumerableExtensions.cs
2025-03-15 14:30:26 -04:00

41 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.Purchasing
{
static class EnumerableExtensions
{
public static IEnumerable<T> NonNull<T>(this IEnumerable<T> enumerable)
{
return enumerable.Where(obj => obj != null);
}
public static IEnumerable<T> IgnoreExceptions<T, TException>(this IEnumerable<T> enumerable,
Action<TException> onException = null) where TException : Exception
{
using var enumerator = enumerable.GetEnumerator();
var hasNext = true;
while (hasNext)
{
try
{
hasNext = enumerator.MoveNext();
}
catch (TException ex)
{
onException?.Invoke(ex);
continue;
}
if (hasNext)
{
yield return enumerator.Current;
}
}
}
}
}