Funny this isn't in the provided Enumerable extension methods.
In any case, here it is:
internal static void Each<T>(this IEnumerable<T> @this, Action<T> action)
{
foreach(T t in @this)
action(t);
}
internal static void Each<T>(this IEnumerable @this, Action<T> action)
{
foreach (object t in @this)
if (t is T)
{
action((T)t);
}
}
An example:
objects.Each(x => DoSomethingFunky(x, "some parameter"));