Class CollectionExtensions
- Namespace
- Cratis.Collections
- Assembly
- Cratis.Fundamentals.dll
Provides a set of extension methods for different collection and enumerable types.
public static class CollectionExtensions
- Inheritance
-
CollectionExtensions
- Inherited Members
Methods
Combine<TKey, TElement>(IEnumerable<ILookup<TKey, TElement>>)
Combines multiple lookups into a single lookup.
public static ILookup<TKey, TElement> Combine<TKey, TElement>(this IEnumerable<ILookup<TKey, TElement>> lookups)
Parameters
lookupsIEnumerable<ILookup<TKey, TElement>>A collection of lookups to combine.
Returns
- ILookup<TKey, TElement>
A single lookup which takes a key into all values with this key in all incoming lookups.
Type Parameters
TKeyThe type of the keys.
TElementThe type of the elements.
CountElements(IEnumerable)
Count number of items from an enumerable.
[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "The enumerable's runtime type implements IEnumerable<> which is a BCL interface always preserved.")]
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "IEnumerable<> interface is a BCL type whose members are preserved by the runtime.")]
[UnconditionalSuppressMessage("AOT", "IL2060", Justification = "MakeGenericMethod is called on Enumerable.Count which is a well-known BCL method.")]
[RequiresDynamicCode("Uses MakeGenericMethod to invoke Enumerable.Count<T> at runtime.")]
public static int CountElements(this IEnumerable enumerable)
Parameters
enumerableIEnumerableEnumerable to count.
Returns
- int
The number of items it enumerates.
Remarks
This method will look for more concrete types and leverage the fastest way to get the count without having to enumerate it. If no other options are available, it will enumerate it.
ForEach<T>(IEnumerable<T>, Action<T>)
Enumerate an enumerable and call the given Action for each item.
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
Parameters
enumerableIEnumerable<T>IEnumerable<T> to enumerate.
actionAction<T>Action<T> to call for each item.
Type Parameters
TItem type.
ToObjectArray(IEnumerable)
Converts an enumerable to an array of objects.
public static object[] ToObjectArray(this IEnumerable enumerable)
Parameters
enumerableIEnumerableEnumerable to convert.
Returns
- object[]
Array of objects.