#if FAT using System; using System.Collections.Generic; namespace LinqInternal.Collections { internal static partial class Extensions { public static IEnumerable After(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterExtracted(source, action); } public static IEnumerable AfterCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterCountedExtracted(source, action); } public static IEnumerable AfterEach(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterEachExtracted(source, action); } public static IEnumerable AfterEach(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterEachExtracted(source, action); } public static IEnumerable AfterEachCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterEachCountedExtracted(source, action); } public static IEnumerable AfterEachCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterEachCountedExtracted(source, action); } public static IEnumerable AfterAny(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterLastExtracted(source, action); } public static IEnumerable AfterAny(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterLastExtracted(source, action); } public static IEnumerable AfterLastCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterLastCountedExtracted(source, action); } public static IEnumerable AfterLastCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : AfterLastCountedExtracted(source, action); } public static IEnumerable Before(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeExtracted(source, action); } public static IEnumerable BeforeEach(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeEachExtracted(source, action); } public static IEnumerable BeforeEach(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeEachExtracted(source, action); } public static IEnumerable BeforeEachCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeEachCountedExtracted(source, action); } public static IEnumerable BeforeEachCounted(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeEachCountedExtracted(source, action); } public static IEnumerable BeforeAny(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeFirstExtracted(source, action); } public static IEnumerable BeforeAny(this IEnumerable source, Action action) { if (source == null) { throw new ArgumentNullException("source"); } return action == null ? source : BeforeFirstExtracted(source, action); } private static IEnumerable AfterCountedExtracted(IEnumerable source, Action action) { var count = 0; foreach (var item in source) { yield return item; count++; } action.Invoke(count); } private static IEnumerable AfterEachCountedExtracted(IEnumerable source, Action action) { var count = 0; foreach (var item in source) { yield return item; action.Invoke(count); count++; } } private static IEnumerable AfterEachCountedExtracted(IEnumerable source, Action action) { var count = 0; foreach (var item in source) { yield return item; action.Invoke(count, item); count++; } } private static IEnumerable AfterEachExtracted(IEnumerable source, Action action) { foreach (var item in source) { yield return item; action.Invoke(); } } private static IEnumerable AfterEachExtracted(IEnumerable source, Action action) { foreach (var item in source) { yield return item; action.Invoke(item); } } private static IEnumerable AfterExtracted(IEnumerable source, Action action) { foreach (var item in source) { yield return item; } action.Invoke(); } private static IEnumerable AfterLastCountedExtracted(IEnumerable source, Action action) { var count = 1; var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { var found = enumerator.Current; yield return found; while (enumerator.MoveNext()) { found = enumerator.Current; yield return enumerator.Current; count++; } action.Invoke(count, found); } } finally { enumerator.Dispose(); } } private static IEnumerable AfterLastCountedExtracted(IEnumerable source, Action action) { var count = 1; var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { yield return enumerator.Current; while (enumerator.MoveNext()) { yield return enumerator.Current; count++; } action.Invoke(count); } } finally { enumerator.Dispose(); } } private static IEnumerable AfterLastExtracted(IEnumerable source, Action action) { var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { var found = enumerator.Current; yield return found; while (enumerator.MoveNext()) { found = enumerator.Current; yield return enumerator.Current; } action.Invoke(found); } } finally { enumerator.Dispose(); } } private static IEnumerable AfterLastExtracted(IEnumerable source, Action action) { var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { yield return enumerator.Current; while (enumerator.MoveNext()) { yield return enumerator.Current; } action.Invoke(); } } finally { enumerator.Dispose(); } } private static IEnumerable BeforeEachCountedExtracted(IEnumerable source, Action action) { var count = 0; foreach (var item in source) { action.Invoke(count); yield return item; count++; } } private static IEnumerable BeforeEachCountedExtracted(IEnumerable source, Action action) { var count = 0; foreach (var item in source) { action.Invoke(count, item); yield return item; count++; } } private static IEnumerable BeforeEachExtracted(IEnumerable source, Action action) { foreach (var item in source) { action.Invoke(); yield return item; } } private static IEnumerable BeforeEachExtracted(IEnumerable source, Action action) { foreach (var item in source) { action.Invoke(item); yield return item; } } private static IEnumerable BeforeExtracted(IEnumerable source, Action action) { action.Invoke(); foreach (var item in source) { yield return item; } } private static IEnumerable BeforeFirstExtracted(IEnumerable source, Action action) { var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { var current = enumerator.Current; action.Invoke(current); yield return current; } else { yield break; } while (enumerator.MoveNext()) { yield return enumerator.Current; } } finally { enumerator.Dispose(); } } private static IEnumerable BeforeFirstExtracted(IEnumerable source, Action action) { var enumerator = source.GetEnumerator(); try { if (enumerator.MoveNext()) { action.Invoke(); yield return enumerator.Current; } else { yield break; } while (enumerator.MoveNext()) { yield return enumerator.Current; } } finally { enumerator.Dispose(); } } } } #endif