In my opinion, creating the new interface seems to be an unnecessary part of this article...
Extensions Methods for
IEnumerable
is the topic of the said article…which is provided by the existing system.
Building a new interface which is not part of the native system is not actually required and is a nice extension of said article, however in my humble opinion is an unnecessary burden to the reader to digest.
Consider the following alternative solutions used by an open source project:
http://dnpextensions.codeplex.com/
It required no new interfaces and provided the same type of logic without the interface.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tools.Utilities
{
public static class EnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> @enum, Action<T> mapFunction)
{
if (null == @enum) throw new ArgumentNullException("@enum");
if (mapFunction == null) throw new ArgumentNullException("mapFunction");
foreach (T item in @enum) mapFunction(item);
}
public static bool IsNullOrEmpty<T>(this IEnumerable<T> iEnumerable)
{
return iEnumerable == null || !iEnumerable.Any();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tools.Utilities
{
public static class ListExtensions
{
public static void RemoveAtFast<T>(this IList<T> _list, int _index)
{
if (_index < 0) return;
int count = _list.Count - 1;
if (_index > count) return;
_list[_index] = _list[count];
_list.RemoveAt(count);
}
public static void ForEach<T>(this IList<T> _list, Action<T> _action)
{
for (int index = 0, end = _list.Count; index < end; index++)
{
_action(_list[index]);
}
}
public static void ForEachWithIndex<T>(this IList<T> _list, Action<T, int> _action)
{
for (int index = 0, end = _list.Count; index < end; index++)
{
_action(_list[index], index);
}
}
public static void ForEachWithIndex<T>(this IList<T> _list, Action<IList<T>, T, int> _action)
{
for (int index = 0, end = _list.Count; index < end; index++)
{
_action(_list, _list[index], index);
}
}
}
}
Otherwise, you really didn’t do much but cite the MSDN article which in my opinion seems to be more informative and direct than this article.