added foreach with index linq.

This commit is contained in:
David Lebee
2018-04-02 11:47:30 -05:00
parent 48db853236
commit f0ed7d9bd5
6 changed files with 354 additions and 223 deletions
@@ -46,5 +46,33 @@ namespace PoweredSoft.DynamicLinq
public static IQueryable GroupBy(this IEnumerable list, Type type, Action<GroupBuilder> callback)
=> list.AsQueryable().GroupBy(type, callback);
public static List<T> Reversed<T>(this List<T> list)
{
var copy = list.ToList();
copy.Reverse();
return copy;
}
public delegate void ForEachDelegate<T>(T element, int index);
public static void ForEach<T>(this List<T> list, ForEachDelegate<T> callback)
{
for (var i = 0; i < list.Count; i++)
callback(list[i], i);
}
public static void ReversedForEach<T>(this List<T> list, Action<T> action)
{
list.Reversed().ForEach(action);
}
public static void ReversedForEach<T>(this List<T> list, ForEachDelegate<T> callback)
{
var reversed = list.Reversed();
reversed.ForEach(callback);
}
}
}