using System;
using System.Collections.Generic;
using System.Linq;
namespace Wayne.Lib
{
///
/// Various extension methods for Enumerables.
///
public static class EnumerableExtensions
{
///
/// Apply an action for each item in an enumerable.
///
///
///
///
public static void ForEach(this IEnumerable enumerable, Action action)
{
foreach (var item in enumerable)
{
action(item);
}
}
///
/// Checks wether a given value is contained in an array of values. Similar to
/// Linq Contains, but the readability of the code is different (Better) depending on the domain.
///
///
///
///
///
public static bool IsIn(this T value, params T[] values)
{
return values.Contains(value);
}
///
/// Returns a sequence that is guaranteed to not be null and not contain null values.
///
///
///
/// Returns all not null items or an empty IEnumerable
public static IEnumerable WhereNotNull(this IEnumerable enumerable)
{
if (enumerable == null)
return new T[] {};
return enumerable.Where(x=> x != null);
}
}
}