CollectionHelper Class
Namespace: PTS
Assembly: PTSframework.dll
Provides a set of static methods for ICollection
type.
Syntax
public static class CollectionHelper
Inheritance
Methods
AddAndReturn<TValue>(ICollection<TValue>, TValue)
Adds an item to collection and returns its instance.
Declaration
public static TValue AddAndReturn<TValue>(this ICollection<TValue> collection, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<TValue> | collection | Collection to add the item to. |
TValue | value | Item to add to collection. |
Returns
Type | Description |
---|---|
TValue | Added item. |
Type Parameters
Name | Description |
---|---|
TValue | The type of elements in the collection. |
AddMultiple<TValue>(ICollection<TValue>, TValue[])
Adds multiple items to collection.
Declaration
public static ICollection<TValue> AddMultiple<TValue>(this ICollection<TValue> collection, params TValue[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<TValue> | collection | Collection to add the items to. |
TValue[] | values | Values to add to the collection. |
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> | The same instance of collection to allow chaining. |
Type Parameters
Name | Description |
---|---|
TValue | The type of elements in the collection. |
Remarks
The method behaves identically to AddRange
method in several native types.
AddNotNull<TValue>(ICollection<TValue>, Nullable<TValue>)
Adds an item to collection if the value type item is not null
.
Declaration
public static ICollection<TValue> AddNotNull<TValue>(this ICollection<TValue> collection, TValue? value)
where TValue : struct
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<TValue> | collection | Collection to add the item to. |
System.Nullable<TValue> | value |
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> | The same instance of collection to allow chaining. |
Type Parameters
Name | Description |
---|---|
TValue | The type of elements in the collection. |
AddRange<TValue>(ICollection<TValue>, IEnumerable<TValue>)
Adds multiple items to collection.
Declaration
public static ICollection<TValue> AddRange<TValue>(this ICollection<TValue> collection, IEnumerable<TValue> values)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<TValue> | collection | Collection to add the items to. |
System.Collections.Generic.IEnumerable<TValue> | values | Values to add to the collection. |
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> | The same instance of collection to allow chaining. |
Type Parameters
Name | Description |
---|---|
TValue | The type of elements in the collection. |
Remarks
The method behaves identically to AddRange
method in several native types.
ToArray<TValue>(ICollection<TValue>)
Copies the elements of the collection to a new array.
Declaration
public static TValue[] ToArray<TValue>(this ICollection<TValue> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<TValue> | collection | The collection to copy into an array. |
Returns
Type | Description |
---|---|
TValue[] | An array containing copies of the elements of the collection. |
Type Parameters
Name | Description |
---|---|
TValue | The type of elements in the collection. |
ToCenteredArray<T>(ICollection<T>)
Copies the elements of the collection to a new array from the middle.
Declaration
public static T[] ToCenteredArray<T>(this ICollection<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<T> | collection | The collection to copy into a centered array. |
Returns
Type | Description |
---|---|
T[] | An array containing copies of the elements of the collection in centered order. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the collection. |