Version 3.3.1.2

LinqExtensions class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public static class LinqExtensions
Various LinQ extensions.
Inheritance
  • System.Object
  • LinqExtensions

Methods

AddRange<T>(HashSet<T>, IEnumerable<T>)
Adds a collection to a hashset.
public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> range)
Parameters
System.Collections.Generic.HashSet<T> hashSet

The hashset.

System.Collections.Generic.IEnumerable<T> range

The collection.

Type Parameters
T

AddRange<T>(IList<T>, IEnumerable<T>)
Adds the elements of the specified collection to the end of the IList<T>.
public static void AddRange<T>(this IList<T> list, IEnumerable<T> collection)
Parameters
System.Collections.Generic.IList<T> list

System.Collections.Generic.IEnumerable<T> collection

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Boolean, T)
Add an item to the end of a collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, bool condition, T append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

T append

The item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Boolean, IEnumerable<T>)
Add a collection to the end of another collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, bool condition, IEnumerable<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

System.Collections.Generic.IEnumerable<T> append

The collection to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Boolean, Func<T>)
Add an item to the end of a collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, bool condition, Func<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

System.Func<T> append

Func to create the item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Func<Boolean>, T)
Add an item to the end of a collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, Func<bool> condition, T append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

T append

The item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Func<Boolean>, IEnumerable<T>)
Add a collection to the end of another collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, Func<bool> condition, IEnumerable<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

System.Collections.Generic.IEnumerable<T> append

The collection to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendIf<T>(IEnumerable<T>, Func<Boolean>, Func<T>)
Add an item to the end of a collection if a condition is met.
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> source, Func<bool> condition, Func<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

System.Func<T> append

Func to create the item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendWith<T>(IEnumerable<T>, T)
Add an item to the end of a collection.
public static IEnumerable<T> AppendWith<T>(this IEnumerable<T> source, T append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

T append

The item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendWith<T>(IEnumerable<T>, IEnumerable<T>)
Add a collection to the end of another collection.
public static IEnumerable<T> AppendWith<T>(this IEnumerable<T> source, IEnumerable<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Collections.Generic.IEnumerable<T> append

The collection to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

AppendWith<T>(IEnumerable<T>, Func<T>)
Add an item to the end of a collection.
public static IEnumerable<T> AppendWith<T>(this IEnumerable<T> source, Func<T> append)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<T> append

Func to create the item to append.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

Convert<T>(IEnumerable, Func<Object, T>)
Convert each item in the collection.
public static IEnumerable<T> Convert<T>(this IEnumerable source, Func<object, T> converter)
Parameters
System.Collections.IEnumerable source

The collection.

System.Func<System.Object, T> converter

Func to convert the items.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

Examine<T>(IEnumerable<T>, Action<T>)
Calls an action on each item before yielding them.
public static IEnumerable<T> Examine<T>(this IEnumerable<T> source, Action<T> action)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Action<T> action

The action to call for each item.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

FilterCast<T>(IEnumerable)
Returns and casts only the items of type T.
public static IEnumerable<T> FilterCast<T>(this IEnumerable source)
Parameters
System.Collections.IEnumerable source

The collection.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

ForEach<T>(IEnumerable<T>, Action<T, Int32>)
Perform an action on each item.
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
Parameters
System.Collections.Generic.IEnumerable<T> source

The source.

System.Action<T, System.Int32> action

The action to perform.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

ForEach<T>(IEnumerable<T>, Action<T>)
Perform an action on each item.
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> action)
Parameters
System.Collections.Generic.IEnumerable<T> source

The source.

System.Action<T> action

The action to perform.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

IsNullOrEmpty<T>(IList<T>)
Returns true if the list is either null or empty. Otherwise false.
public static bool IsNullOrEmpty<T>(this IList<T> list)
Parameters
System.Collections.Generic.IList<T> list

The list.

Returns
System.Boolean

Type Parameters
T

Populate<T>(IList<T>, T)
Sets all items in the list to the given value.
public static void Populate<T>(this IList<T> list, T item)
Parameters
System.Collections.Generic.IList<T> list

The list.

T item

The value.

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Boolean, T)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, bool condition, T prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

T prepend

The item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Boolean, IEnumerable<T>)
Add a collection to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, bool condition, IEnumerable<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

System.Collections.Generic.IEnumerable<T> prepend

The collection to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Boolean, Func<T>)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, bool condition, Func<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Boolean condition

The condition.

System.Func<T> prepend

Func to create the item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<Boolean>, T)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<bool> condition, T prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

T prepend

The item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<Boolean>, IEnumerable<T>)
Add a collection to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<bool> condition, IEnumerable<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

System.Collections.Generic.IEnumerable<T> prepend

The collection to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<Boolean>, Func<T>)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<bool> condition, Func<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Boolean> condition

The condition.

System.Func<T> prepend

Func to create the item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<IEnumerable<T>, Boolean>, T)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<IEnumerable<T>, bool> condition, T prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Collections.Generic.IEnumerable<T>, System.Boolean> condition

The condition.

T prepend

The item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<IEnumerable<T>, Boolean>, IEnumerable<T>)
Add a collection to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<IEnumerable<T>, bool> condition, IEnumerable<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Collections.Generic.IEnumerable<T>, System.Boolean> condition

The condition.

System.Collections.Generic.IEnumerable<T> prepend

The collection to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependIf<T>(IEnumerable<T>, Func<IEnumerable<T>, Boolean>, Func<T>)
Add an item to the beginning of another collection, if a condition is met.
public static IEnumerable<T> PrependIf<T>(this IEnumerable<T> source, Func<IEnumerable<T>, bool> condition, Func<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<System.Collections.Generic.IEnumerable<T>, System.Boolean> condition

The condition.

System.Func<T> prepend

Func to create the item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependWith<T>(IEnumerable<T>, T)
Add an item to the beginning of a collection.
public static IEnumerable<T> PrependWith<T>(this IEnumerable<T> source, T prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

T prepend

The item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependWith<T>(IEnumerable<T>, IEnumerable<T>)
Add a collection to the beginning of another collection.
public static IEnumerable<T> PrependWith<T>(this IEnumerable<T> source, IEnumerable<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Collections.Generic.IEnumerable<T> prepend

The collection to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

PrependWith<T>(IEnumerable<T>, Func<T>)
Add an item to the beginning of a collection.
public static IEnumerable<T> PrependWith<T>(this IEnumerable<T> source, Func<T> prepend)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

System.Func<T> prepend

Func to create the item to prepend.

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

Sort<T>(IList<T>)
Sorts an IList
public static void Sort<T>(this IList<T> list)
Parameters
System.Collections.Generic.IList<T> list

Type Parameters
T

Sort<T>(IList<T>, Comparison<T>)
Sorts an IList
public static void Sort<T>(this IList<T> list, Comparison<T> comparison)
Parameters
System.Collections.Generic.IList<T> list

System.Comparison<T> comparison

Type Parameters
T

ToImmutableList<T>(IEnumerable<T>)
Convert a collection to an immutable list.
public static ImmutableList<T> ToImmutableList<T>(this IEnumerable<T> source)
Parameters
System.Collections.Generic.IEnumerable<T> source

The collection.

Returns
ImmutableList<T>

Type Parameters
T