using System;
using System.Collections.Generic;
using System.Text;
namespace System.Linq
{
public static class GenericEachExtension
{
public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T t in source)
{
action.Invoke(t);
}
return source;
}
public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, bool> action)
{
foreach (T t in source)
{
if (!action.Invoke(t)) break;
}
return source;
}
public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T, int> action)
{
int i = 0;
foreach (T t in source)
{
action.Invoke(t, i);
i++;
}
return source;
}
public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, int, bool> action)
{
int i = 0;
foreach (T t in source)
{
if (!action.Invoke(t, i)) break;
i++;
}
return source;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace System.Collections
{
public static class EachExtension
{
public static IEnumerable Each<T>(this IEnumerable source, Action<T> action)
{
foreach (T t in source)
{
action.Invoke(t);
}
return source;
}
public static IEnumerable Each<T>(this IEnumerable source, Func<T, bool> action)
{
foreach (T t in source)
{
if (!action.Invoke(t)) break;
}
return source;
}
public static IEnumerable Each<T>(this IEnumerable source, Action<T, int> action)
{
int i = 0;
foreach (T t in source)
{
action.Invoke(t, i);
i++;
}
return source;
}
public static IEnumerable Each<T>(this IEnumerable source, Func<T, int, bool> action)
{
int i = 0;
foreach (T t in source)
{
if (!action.Invoke(t, i)) break;
i++;
}
return source;
}
public static IEnumerable Each(this IEnumerable source, Action<object> action)
{
foreach (object t in source)
{
action.Invoke(t);
}
return source;
}
public static IEnumerable Each(this IEnumerable source, Func<object, bool> action)
{
foreach (object t in source)
{
if (!action.Invoke(t)) break;
}
return source;
}
public static IEnumerable Each(this IEnumerable source, Action<object, int> action)
{
int i = 0;
foreach (object t in source)
{
action.Invoke(t, i);
i++;
}
return source;
}
public static IEnumerable Each(this IEnumerable source, Func<object, int, bool> action)
{
int i = 0;
foreach (object t in source)
{
if (!action.Invoke(t, i)) break;
i++;
}
return source;
}
}
}