using System; using System.Collections.Generic; namespace Umbraco.ModelsBuilder { public static class EnumerableExtensions { public static void RemoveAll(this IList list, Func predicate) { for (var i = 0; i < list.Count; i++) { if (predicate(list[i])) { list.RemoveAt(i--); // i-- is important here! } } } public static IEnumerable And(this IEnumerable enumerable, T item) { foreach (var x in enumerable) yield return x; yield return item; } public static IEnumerable AndIfNotNull(this IEnumerable enumerable, T item) where T : class { foreach (var x in enumerable) yield return x; if (item != null) yield return item; } } }