Skip to main content

EnumerableExtensions

Assembly: ServiceStack.Common.dll
View Source
Declaration
public static class EnumerableExtensions

Methods

IsEmpty<T>(ICollection<T>)

View Source
Declaration
public static bool IsEmpty<T>(this ICollection<T> collection)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.ICollection<<T>>collection
Type Parameters
  • T

IsEmpty<T>(T[])

View Source
Declaration
public static bool IsEmpty<T>(this T[] collection)
Returns

System.Boolean

Parameters
TypeName
<T>[]collection
Type Parameters
  • T

ToHashSet<T>(IEnumerable<T>)

View Source
Declaration
[Obsolete("Use ToSet() or 'using System.Linq;'")]
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> items)
Returns

System.Collections.Generic.HashSet<<T>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>items
Type Parameters
  • T

ToSet<T>(IEnumerable<T>)

View Source
Declaration
public static HashSet<T> ToSet<T>(this IEnumerable<T> items)
Returns

System.Collections.Generic.HashSet<<T>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>items
Type Parameters
  • T

ToSet<T>(IEnumerable<T>, IEqualityComparer<T>)

View Source
Declaration
public static HashSet<T> ToSet<T>(this IEnumerable<T> items, IEqualityComparer<T> comparer)
Returns

System.Collections.Generic.HashSet<<T>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>items
System.Collections.Generic.IEqualityComparer<<T>>comparer
Type Parameters
  • T

Each<T>(IEnumerable<T>, Action<T>)

View Source
Declaration
public static void Each<T>(this IEnumerable<T> values, Action<T> action)
Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>values
System.Action<<T>>action
Type Parameters
  • T

Each<T>(IEnumerable<T>, Action<Int32, T>)

View Source
Declaration
public static void Each<T>(this IEnumerable<T> values, Action<int, T> action)
Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>values
System.Action<System.Int32,<T>>action
Type Parameters
  • T

Each<TKey, TValue>(IDictionary<TKey, TValue>, Action<TKey, TValue>)

View Source
Declaration
public static void Each<TKey, TValue>(this IDictionary<TKey, TValue> map, Action<TKey, TValue> action)
Parameters
TypeName
System.Collections.Generic.IDictionary<<TKey>,<TValue>>map
System.Action<<TKey>,<TValue>>action
Type Parameters
  • TKey
  • TValue

Map<To, From>(IEnumerable<From>, Func<From, To>)

View Source
Declaration
public static List<To> Map<To, From>(this IEnumerable<From> items, Func<From, To> converter)
Returns

System.Collections.Generic.List<<To>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<From>>items
System.Func<<From>,<To>>converter
Type Parameters
  • To
  • From

Map<To>(IEnumerable, Func<Object, To>)

View Source
Declaration
public static List<To> Map<To>(this IEnumerable items, Func<object, To> converter)
Returns

System.Collections.Generic.List<<To>>

Parameters
TypeName
System.Collections.IEnumerableitems
System.Func<System.Object,<To>>converter
Type Parameters
  • To

ToObjects<T>(IEnumerable<T>)

View Source
Declaration
public static List<object> ToObjects<T>(this IEnumerable<T> items)
Returns

System.Collections.Generic.List<System.Object>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>items
Type Parameters
  • T

FirstNonDefaultOrEmpty(IEnumerable<String>)

View Source
Declaration
public static string FirstNonDefaultOrEmpty(this IEnumerable<string> values)
Returns

System.String

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.String>values

FirstNonDefault<T>(IEnumerable<T>)

View Source
Declaration
public static T FirstNonDefault<T>(this IEnumerable<T> values)
Returns

<T>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>values
Type Parameters
  • T

EquivalentTo(Byte[], Byte[])

View Source
Declaration
public static bool EquivalentTo(this byte[] bytes, byte[] other)
Returns

System.Boolean

Parameters
TypeName
System.Byte[]bytes
System.Byte[]other

EquivalentTo<T>(T[], T[], Func<T, T, Boolean>)

View Source
Declaration
public static bool EquivalentTo<T>(this T[] array, T[] otherArray, Func<T, T, bool> comparer = null)
Returns

System.Boolean

Parameters
TypeName
<T>[]array
<T>[]otherArray
System.Func<<T>,<T>,System.Boolean>comparer
Type Parameters
  • T

EquivalentTo<T>(IEnumerable<T>, IEnumerable<T>, Func<T, T, Boolean>)

View Source
Declaration
public static bool EquivalentTo<T>(this IEnumerable<T> thisList, IEnumerable<T> otherList, Func<T, T, bool> comparer = null)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>thisList
System.Collections.Generic.IEnumerable<<T>>otherList
System.Func<<T>,<T>,System.Boolean>comparer
Type Parameters
  • T

EquivalentTo<K, V>(IDictionary<K, V>, IDictionary<K, V>, Func<V, V, Boolean>)

View Source
Declaration
public static bool EquivalentTo<K, V>(this IDictionary<K, V> a, IDictionary<K, V> b, Func<V, V, bool> comparer = null)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.IDictionary<<K>,<V>>a
System.Collections.Generic.IDictionary<<K>,<V>>b
System.Func<<V>,<V>,System.Boolean>comparer
Type Parameters
  • K
  • V

BatchesOf<T>(IEnumerable<T>, Int32)

View Source
Declaration
public static IEnumerable<T[]> BatchesOf<T>(this IEnumerable<T> sequence, int batchSize)
Returns

System.Collections.Generic.IEnumerable<<T>[]>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>sequence
System.Int32batchSize
Type Parameters
  • T

ToSafeDictionary<T, TKey>(IEnumerable<T>, Func<T, TKey>)

View Source
Declaration
public static Dictionary<TKey, T> ToSafeDictionary<T, TKey>(this IEnumerable<T> list, Func<T, TKey> expr)
Returns

System.Collections.Generic.Dictionary<<TKey>,<T>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>list
System.Func<<T>,<TKey>>expr
Type Parameters
  • T
  • TKey

ToDictionary<T, TKey, TValue>(IEnumerable<T>, Func<T, KeyValuePair<TKey, TValue>>)

View Source
Declaration
public static Dictionary<TKey, TValue> ToDictionary<T, TKey, TValue>(this IEnumerable<T> list, Func<T, KeyValuePair<TKey, TValue>> map)
Returns

System.Collections.Generic.Dictionary<<TKey>,<TValue>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>list
System.Func<<T>,System.Collections.Generic.KeyValuePair<<TKey>,<TValue>>>map
Type Parameters
  • T
  • TKey
  • TValue

Safe<T>(IEnumerable<T>)

Return T[0] when enumerable is null, safe to use in enumerations like foreach

View Source
Declaration
public static IEnumerable<T> Safe<T>(this IEnumerable<T> enumerable)
Returns

System.Collections.Generic.IEnumerable<<T>>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>enumerable
Type Parameters
  • T

Safe(IEnumerable)

View Source
Declaration
public static IEnumerable Safe(this IEnumerable enumerable)
Returns

System.Collections.IEnumerable

Parameters
TypeName
System.Collections.IEnumerableenumerable

AllAsync<T>(IEnumerable<T>, Func<T, Task<Boolean>>)

View Source
Declaration
public static async Task<bool> AllAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>source
System.Func<<T>,System.Threading.Tasks.Task<System.Boolean>>predicate
Type Parameters
  • T

AllAsync<T>(IEnumerable<Task<T>>, Func<T, Boolean>)

View Source
Declaration
public static async Task<bool> AllAsync<T>(this IEnumerable<Task<T>> source, Func<T, bool> predicate)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<<T>>>source
System.Func<<T>,System.Boolean>predicate
Type Parameters
  • T

AnyAsync<T>(IEnumerable<T>, Func<T, Task<Boolean>>)

View Source
Declaration
public static async Task<bool> AnyAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
System.Collections.Generic.IEnumerable<<T>>source
System.Func<<T>,System.Threading.Tasks.Task<System.Boolean>>predicate
Type Parameters
  • T

AnyAsync<T>(IEnumerable<Task<T>>, Func<T, Boolean>)

View Source
Declaration
public static async Task<bool> AnyAsync<T>(this IEnumerable<Task<T>> source, Func<T, bool> predicate)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<<T>>>source
System.Func<<T>,System.Boolean>predicate
Type Parameters
  • T

AllKeysWithDefaultValues(IEnumerable)

View Source
Declaration
public static List<string> AllKeysWithDefaultValues(IEnumerable collection)
Returns

System.Collections.Generic.List<System.String>

Parameters
TypeName
System.Collections.IEnumerablecollection

FirstElementType(IEnumerable, String)

View Source
Declaration
public static Type FirstElementType(IEnumerable collection, string key)
Returns

System.Type

Parameters
TypeName
System.Collections.IEnumerablecollection
System.Stringkey

CombineDistinct<T>(T[], T[][])

View Source
Declaration
public static T[] CombineDistinct<T>(this T[] original, params T[][] others)
Returns

<T>[]

Parameters
TypeName
<T>[]original
<T>[][]others
Type Parameters
  • T

CombineSet<T>(T[], T[][])

View Source
Declaration
public static HashSet<T> CombineSet<T>(this T[] original, params T[][] others)
Returns

System.Collections.Generic.HashSet<<T>>

Parameters
TypeName
<T>[]original
<T>[][]others
Type Parameters
  • T