using PoweredSoft.DynamicLinq.Fluent; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace PoweredSoft.DynamicLinq { public static class EnumerableExtensions { public static IEnumerable Where(this IEnumerable list, string path, ConditionOperators conditionOperator, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null) => list.AsQueryable().Where(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision); public static IEnumerable Where(this IEnumerable list, Action callback) => list.Query(callback); public static IEnumerable Query(this IEnumerable list, Action callback) => list.AsQueryable().Query(callback); public static IEnumerable Sort(this IEnumerable list, string path, QueryOrderByDirection sortDirection, bool appendSort) => list.AsQueryable().OrderBy(path, sortDirection, appendSort); public static IEnumerable OrderBy(this IEnumerable list, string path) => list.AsQueryable().OrderBy(path); public static IEnumerable OrderByDescending(this IEnumerable list, string path) => list.AsQueryable().OrderByDescending(path); public static IEnumerable ThenBy(this IEnumerable list, string path) => list.AsQueryable().ThenBy(path); public static IEnumerable ThenByDescending(this IEnumerable list, string path) => list.AsQueryable().ThenByDescending(path); public static IQueryable GroupBy(this IEnumerable list, string path) => list.AsQueryable().GroupBy(typeof(T), path); public static IQueryable GroupBy(this IEnumerable list, Type type, string path) => list.AsQueryable().GroupBy(type, path); public static IQueryable GroupBy(this IEnumerable list, Action callback) => list.AsQueryable().GroupBy(typeof(T), callback); public static IQueryable GroupBy(this IEnumerable list, Type type, Action callback) => list.AsQueryable().GroupBy(type, callback); public static IQueryable EmptyGroupBy(this IEnumerable list, Type underlyingType) => list.AsQueryable().EmptyGroupBy(underlyingType); public static List Reversed(this List list) { var copy = list.ToList(); copy.Reverse(); return copy; } public delegate void ForEachDelegate(T element, int index); public static void ForEach(this List list, ForEachDelegate callback) { for (var i = 0; i < list.Count; i++) callback(list[i], i); } public static void ReversedForEach(this List list, Action action) { list.Reversed().ForEach(action); } public static void ReversedForEach(this List list, ForEachDelegate callback) { for (var i = list.Count - 1; i >= 0; i--) callback(list[i], i); } } }