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
source
IEnumerable<T>The collection to check for containment.
items
IEnumerable<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
T
The 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
source
IEnumerable<T>The collection to check for containment.
items
IEnumerable<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
T
The 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
source
IEnumerable<T>The collection to check.
Returns
- bool
True if the collection contains no elements; otherwise, false.
Type Parameters
T
The 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
source
IEnumerable<T>The collection to check.
Returns
- bool
True if the collection is null or contains no elements; otherwise, false.
Type Parameters
T
The 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
source
IEnumerable<T>toPrepend
IEnumerable<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
source
IEnumerable<T>The collection to shuffle.
target
TTargetThe target collection to which the shuffled elements will be added.
Returns
- TTarget
The target collection with the shuffled elements added.
Type Parameters
T
The type of elements in the collection.
TTarget
The 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
source
IEnumerable<T>The collection to shuffle.
Returns
- List<T>
A new list containing the shuffled elements.
Type Parameters
T
The 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
source
IEnumerable<T>The collection to shuffle.
Returns
- IEnumerable<T>
A new collection with the elements shuffled randomly.
Type Parameters
T
The 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
source
IEnumerable<TSource>The collection to convert to a map.
keySelector
Func<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
TSource
The type of elements in the source collection.
TKey
The 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
source
IEnumerable<TSource>The collection to convert to a map.
keySelector
Func<TSource, TKey>Key selector function to extract the key from each element.
elementSelector
Func<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
TSource
The type of elements in the source collection.
TKey
The type of keys in the resulting map.
TElement
The 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
source
IEnumerable<TSource>The collection to convert to a map.
keySelector
Func<TSource, TKey>Key selector function to extract the key from each element.
elementSelector
Func<TSource, TElement>Element selector function to extract the value from each element.
comparer
IEqualityComparer<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
TSource
The type of elements in the source collection.
TKey
The type of keys in the resulting map.
TElement
The 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
enumerable
IEnumerable<T>The collection to convert to a string.
func
Func<T, string>The function to apply to each element to convert it to a string.
separator
stringThe 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
T
The 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
source
IEnumerable<T>The collection to convert to a string.
separator
stringThe 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
T
The type of elements in the collection.