Class EnumerableExtensions
- Namespace
- RisingV.Shared.Extensions
- Assembly
- RisingV.Shared.dll
Provides extension methods for working with IEnumerable<T> collections.
public static class EnumerableExtensions
- Inheritance
-
EnumerableExtensions
- Inherited Members
Methods
ContainsAll<T>(IEnumerable<T>?, IEnumerable<T>?)
Checks if the specified collection contains all elements from another collection.
public static bool ContainsAll<T>(this IEnumerable<T>? source, IEnumerable<T>? items)
Parameters
sourceIEnumerable<T>The collection to check for containment.
itemsIEnumerable<T>The collection of items to check for in the source collection.
Returns
- bool
True if the source collection contains all elements from the items collection; otherwise, false.
Type Parameters
TThe type of elements in the collections.
ContainsAny<T>(IEnumerable<T>?, IEnumerable<T>?)
Checks if the specified collection contains any elements from another collection.
public static bool ContainsAny<T>(this IEnumerable<T>? source, IEnumerable<T>? items)
Parameters
sourceIEnumerable<T>The collection to check for containment.
itemsIEnumerable<T>The collection of items to check for in the source collection.
Returns
- bool
True if the source collection contains any elements from the items collection; otherwise, false.
Type Parameters
TThe type of elements in the collections.
IsEmpty<T>(IEnumerable<T>)
Checks if the specified collection is empty (contains no elements).
public static bool IsEmpty<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The collection to check.
Returns
- bool
True if the collection contains no elements; otherwise, false.
Type Parameters
TThe type of elements in the collection.
IsNullOrEmpty<T>(IEnumerable<T>?)
Checks if the specified collection is null or empty.
public static bool IsNullOrEmpty<T>(this IEnumerable<T>? source)
Parameters
sourceIEnumerable<T>The collection to check.
Returns
- bool
True if the collection is null or contains no elements; otherwise, false.
Type Parameters
TThe type of elements in the collection.
PrependRange<T>(IEnumerable<T>, IEnumerable<T>)
Returns a sequence whose elements are all the items in toPrepend
followed by all the items in source.
public static IEnumerable<T> PrependRange<T>(this IEnumerable<T> source, IEnumerable<T> toPrepend)
Parameters
sourceIEnumerable<T>toPrependIEnumerable<T>
Returns
- IEnumerable<T>
Type Parameters
T
ShuffleInto<T, TTarget>(IEnumerable<T>, TTarget)
Shuffles the elements of the specified collection into a target collection.
public static TTarget ShuffleInto<T, TTarget>(this IEnumerable<T> source, TTarget target) where TTarget : ICollection<T>
Parameters
sourceIEnumerable<T>The collection to shuffle.
targetTTargetThe target collection to which the shuffled elements will be added.
Returns
- TTarget
The target collection with the shuffled elements added.
Type Parameters
TThe type of elements in the collection.
TTargetThe type of the target collection, which must implement ICollection<T>.
ShuffleToList<T>(IEnumerable<T>)
Shuffles the elements of the specified collection into a new list.
public static List<T> ShuffleToList<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The collection to shuffle.
Returns
- List<T>
A new list containing the shuffled elements.
Type Parameters
TThe type of elements in the collection.
Shuffle<T>(IEnumerable<T>)
Shuffles the elements of the specified collection randomly.
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The collection to shuffle.
Returns
- IEnumerable<T>
A new collection with the elements shuffled randomly.
Type Parameters
TThe type of elements in the collection.
ToMap<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>?)
Converts the elements of the specified collection to a Map<TKey, TValue> using the specified key selector.
public static Map<TKey, TSource> ToMap<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey>? keySelector = null) where TKey : notnull
Parameters
sourceIEnumerable<TSource>The collection to convert to a map.
keySelectorFunc<TSource, TKey>Key selector function to extract the key from each element.
Returns
- Map<TKey, TSource>
A Map<TKey, TValue> containing the keys and elements from the source collection.
Type Parameters
TSourceThe type of elements in the source collection.
TKeyThe type of keys in the resulting map.
ToMap<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)
Converts the elements of the specified collection to a Map<TKey, TValue> using the specified key and element selectors.
public static Map<TKey, TElement> ToMap<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TKey : notnull
Parameters
sourceIEnumerable<TSource>The collection to convert to a map.
keySelectorFunc<TSource, TKey>Key selector function to extract the key from each element.
elementSelectorFunc<TSource, TElement>Element selector function to extract the value from each element.
Returns
- Map<TKey, TElement>
A Map<TKey, TValue> containing the keys and elements from the source collection.
Type Parameters
TSourceThe type of elements in the source collection.
TKeyThe type of keys in the resulting map.
TElementThe type of elements in the resulting map.
ToMap<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>?)
Converts the elements of the specified collection to a Map<TKey, TValue> using the specified key and element selectors,
public static Map<TKey, TElement> ToMap<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer) where TKey : notnull
Parameters
sourceIEnumerable<TSource>The collection to convert to a map.
keySelectorFunc<TSource, TKey>Key selector function to extract the key from each element.
elementSelectorFunc<TSource, TElement>Element selector function to extract the value from each element.
comparerIEqualityComparer<TKey>Optional equality comparer for the keys in the resulting map.
Returns
- Map<TKey, TElement>
A Map<TKey, TValue> containing the keys and elements from the source collection.
Type Parameters
TSourceThe type of elements in the source collection.
TKeyThe type of keys in the resulting map.
TElementThe type of elements in the resulting map.
ToStringBy<T>(IEnumerable<T>, Func<T, string>, string)
Converts the elements of the specified collection to a string using a specified function to format each element, with a specified separator.
public static string ToStringBy<T>(this IEnumerable<T> enumerable, Func<T, string> func, string separator = ", ")
Parameters
enumerableIEnumerable<T>The collection to convert to a string.
funcFunc<T, string>The function to apply to each element to convert it to a string.
separatorstringThe separator to use between elements in the resulting string.
Returns
- string
A string representation of the collection, with each element formatted by the specified function and separated by the specified separator.
Type Parameters
TThe type of elements in the collection.
ToStringBy<T>(IEnumerable<T>, string)
Converts the elements of the specified collection to a string, using a specified separator.
public static string ToStringBy<T>(this IEnumerable<T> source, string separator = ", ")
Parameters
sourceIEnumerable<T>The collection to convert to a string.
separatorstringThe separator to use between elements in the resulting string.
Returns
- string
A string representation of the collection, with elements separated by the specified separator.
Type Parameters
TThe type of elements in the collection.