using System; using System.Collections.Generic; using System.Linq; namespace Znyc.Recruitment.Admin.Commons.Linq { public static class EnumerableExtentions { public static T[] AsToArray(this IEnumerable source, bool isNullAsEmpty = false) { if (source == null) { return isNullAsEmpty ? new T[0] : null; } return source as T[] ?? source.ToArray(); } public static List AsToList(this IEnumerable source, bool isNullAsEmpty = false) { if (source == null) { return isNullAsEmpty ? new List() : null; } return source as List ?? source.ToList(); } public static void ForEach(this IEnumerable source, Action process) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (process == null) { throw new ArgumentNullException(nameof(process)); } foreach (T item in source) { process(item); } } public static void ForEach(this IEnumerable source, Func process) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (process == null) { throw new ArgumentNullException(nameof(process)); } foreach (T item in source) { process(item); } } } }