using System; using System.Collections.Generic; using System.ComponentModel; namespace Xamarin.Forms.Internals { [EditorBrowsable(EditorBrowsableState.Never)] public static class EnumerableExtensions { public static IEnumerable GetGesturesFor(this IEnumerable gestures, Func predicate = null) where T : GestureRecognizer { if (gestures == null) yield break; if (predicate == null) predicate = x => true; foreach (IGestureRecognizer item in gestures) { var gesture = item as T; if (gesture != null && predicate(gesture)) { yield return gesture; } } } internal static IEnumerable Append(this IEnumerable enumerable, T item) { foreach (T x in enumerable) yield return x; yield return item; } public static void ForEach(this IEnumerable enumeration, Action action) { foreach (T item in enumeration) { action(item); } } public static int IndexOf(this IEnumerable enumerable, T item) { if (enumerable == null) throw new ArgumentNullException("enumerable"); var i = 0; foreach (T element in enumerable) { if (Equals(element, item)) return i; i++; } return -1; } public static int IndexOf(this IEnumerable enumerable, Func predicate) { var i = 0; foreach (T element in enumerable) { if (predicate(element)) return i; i++; } return -1; } public static IEnumerable Prepend(this IEnumerable enumerable, T item) { yield return item; foreach (T x in enumerable) yield return x; } } }