Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created June 8, 2011 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developernotes/1015445 to your computer and use it in GitHub Desktop.
Save developernotes/1015445 to your computer and use it in GitHub Desktop.
Enumeration extensions
public static void WhenNotNullPerform<TType, TResult>(this IEnumerable<TType> items, Func<TType, TResult> conditionToCheck, Action<TResult> actionToApply) where TResult : class
{
items.Each(x =>
{
var result = conditionToCheck.Invoke(x);
if (result != null)
{
actionToApply.Invoke(result);
}
});
}
public static void Each<TType>(this IEnumerable<TType> items, Action<TType> action)
{
foreach (var item in items) {
action(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment