Class CollectionExtensions
Extensions for all elements of type ICollection<T>.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class CollectionExtensions
Methods
| Edit this page View SourceAddClone<T>(ICollection<T>, T)
Clones an element and adds the copy to a collection.
Declaration
public static void AddClone<T>(this ICollection<T> collection, T item) where T : ICloneable
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to which to add the elements. |
T | item | Element to copy and add to the collection. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
AddClones<T>(ICollection<T>, IEnumerable<T>)
Adds a copy of a set of elements to the ICollection<T>.
Declaration
public static void AddClones<T>(this ICollection<T> collection, IEnumerable<T> source) where T : ICloneable
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to which to add the elements. |
IEnumerable<T> | source | Elements to add to the collection. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
AddRangeAsync<T>(ICollection<T>, IAsyncEnumerable<T>)
Adds a set of elements to the specified ICollection<T>.
Declaration
public static Task AddRangeAsync<T>(this ICollection<T> collection, IAsyncEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection onto which to add the elements. |
IAsyncEnumerable<T> | items | Async enumeration of elements to be added to the collection. |
Returns
Type | Description |
---|---|
Task |
Type Parameters
Name | Description |
---|---|
T | Type of elements contained in the collection. |
AddRange<T>(ICollection<T>, IEnumerable<T>)
Adds a set of elements to the specified ICollection<T>.
Declaration
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection onto which to add the elements. |
IEnumerable<T> | items | Enumeration of elements to be added to the collection. |
Type Parameters
Name | Description |
---|---|
T | Type of elements contained in the collection. |
PopFirst<T>(ICollection<T>)
Returns the first element in the list, removing it.
Declaration
public static T PopFirst<T>(this ICollection<T> a)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | a | List from which to get the element. |
Returns
Type | Description |
---|---|
T | The first element in the list. |
Type Parameters
Name | Description |
---|---|
T | Type of elements contained in the ICollection<T>. |
Pop<T>(ICollection<T>)
Returns the last element in the list, removing it.
Declaration
public static T Pop<T>(this ICollection<T> a)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | a | List from which to get the element. |
Returns
Type | Description |
---|---|
T | The last element in the list. |
Type Parameters
Name | Description |
---|---|
T | Type of elements contained in the ICollection<T>. |
PushInto<TItem, TCollection>(TItem, ICollection<TCollection>)
Alternative to Add(T) with support for fluent syntax.
Declaration
public static TItem PushInto<TItem, TCollection>(this TItem value, ICollection<TCollection> collection) where TItem : TCollection
Parameters
Type | Name | Description |
---|---|---|
TItem | value | Value to add to the collection. |
ICollection<TCollection> | collection | Collection to which to add the new element. |
Returns
Type | Description |
---|---|
TItem | The object added to the collection. |
Type Parameters
Name | Description |
---|---|
TItem | Type of element to add to the collection. |
TCollection | Type of elements contained in the ICollection<T>. |
Push<T>(ICollection<T>)
Alternative to Add(T) with support for fluent syntax.
Declaration
public static T Push<T>(this ICollection<T> collection) where T : new()
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to which to add the new element. |
Returns
Type | Description |
---|---|
T | A new instance of |
Type Parameters
Name | Description |
---|---|
T | Type of elements contained in the ICollection<T>. |
Push<TItem, TCollection>(ICollection<TCollection>)
Alternative to Add(T) with support for fluent syntax.
Declaration
public static TItem Push<TItem, TCollection>(this ICollection<TCollection> collection) where TItem : TCollection, new()
Parameters
Type | Name | Description |
---|---|---|
ICollection<TCollection> | collection | Collection to which to add the new element. |
Returns
Type | Description |
---|---|
TItem | A new instance of type |
Type Parameters
Name | Description |
---|---|
TItem | Type of element to add to the collection. |
TCollection | Type of elements contained in the ICollection<T>. |
Push<TItem, TCollection>(ICollection<TCollection>, TItem)
Alternative to Add(T) with support for fluent syntax.
Declaration
public static TItem Push<TItem, TCollection>(this ICollection<TCollection> collection, TItem value) where TItem : TCollection
Parameters
Type | Name | Description |
---|---|---|
ICollection<TCollection> | collection | Collection to which to add the new element. |
TItem | value | Value to add to the collection. |
Returns
Type | Description |
---|---|
TItem | The object added to the collection. |
Type Parameters
Name | Description |
---|---|
TItem | Type of element to add to the collection. |
TCollection | Type of elements contained in the ICollection<T>. |
RemoveAll<T>(ICollection<T>)
Removes all elements from a collection, individually.
Declaration
public static void RemoveAll<T>(this ICollection<T> collection)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to process. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
RemoveAll<T>(ICollection<T>, in Action<T>)
Removes all elements from a collection.
Declaration
public static void RemoveAll<T>(this ICollection<T> collection, in Action<T> beforeDelete)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to process. |
Action<T> | beforeDelete | Action to execute before deleting a particular element. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
RemoveAll<T>(ICollection<T>, in Predicate<T>)
Removes all elements from a collection that satisfy a condition.
Declaration
public static void RemoveAll<T>(this ICollection<T> collection, in Predicate<T> check)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to process. |
Predicate<T> | check | Function that verifies if an element satisfies a condition. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
RemoveAll<T>(ICollection<T>, in Predicate<T>?, in Action<T>?)
Removes all elements from a collection that satisfy a condition.
Declaration
public static void RemoveAll<T>(this ICollection<T> collection, in Predicate<T>? check, in Action<T>? beforeDelete)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | Collection to process. |
Predicate<T> | check | Function that verifies if an element satisfies a condition. |
Action<T> | beforeDelete | Action to execute before deleting a particular element. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the collection. |
RemoveOf<TItem, TRemove>(ICollection<TItem>)
Removes all elements of the specified type from the collection.
Declaration
public static void RemoveOf<TItem, TRemove>(this ICollection<TItem> collection) where TRemove : TItem
Parameters
Type | Name | Description |
---|---|---|
ICollection<TItem> | collection | Collection from which to remove the elements. |
Type Parameters
Name | Description |
---|---|
TItem | Type of elements contained in the collection. |
TRemove | Type of elements to remove. |