using System; using System.Collections; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Text; namespace EasyDevCore.Common { /// /// /// public static class LinqExtensions { /// /// Indexes the of. /// /// The type of the source. /// The source. /// The item. /// public static int IndexOf(this IEnumerable source, TSource item) { int index = 0; foreach (TSource sourceItem in source) { if ((item == null && sourceItem == null) || (sourceItem != null && sourceItem.Equals(item))) return index; index++; } return -1; } /// /// Fors the each. /// /// The type of the source. /// The source. /// The action. /// public static IEnumerable ForEach(this IEnumerable source, Action action) { foreach (var item in source) action(item); return source; } /// /// Fors the each. /// /// The type of the source. /// The source. /// The action. /// public static IEnumerable ForEach(this IEnumerable source, Action action) { foreach (var item in source) action((TSource)item); return source; } /// /// Firsts the value. /// /// The type of the t source. /// /// The source. /// The predicate. /// The selector. /// V. public static V FirstValue(this IEnumerable source, Func predicate, Func selector) { #pragma warning disable CS8604 // Possible null reference argument. return selector(source.FirstOrDefault(predicate)); #pragma warning restore CS8604 // Possible null reference argument. } /// /// Firsts the value. /// /// The type of the t source. /// /// The source. /// The selector. /// V. public static V FirstValue(this IEnumerable source, Func selector) { #pragma warning disable CS8604 // Possible null reference argument. return selector(source.FirstOrDefault()); #pragma warning restore CS8604 // Possible null reference argument. } /// /// Maps the specified selector. /// /// The type of the source. /// The type of the result. /// The source. /// The selector. /// ///
///
public static IEnumerable Map(this IEnumerable source, Func selector) => source.Select(selector); } }