Class CollectionUtility
public static class CollectionUtility
- Inheritance
-
CollectionUtility
- Inherited Members
Methods
AddOrUpdate<TKey, TValue>(ConcurrentDictionary<TKey, TValue>, TKey, TValue, out TValue)
Updates the value in a ConcurrentDictionary<TKey, TValue> and returns the old value.
public static bool AddOrUpdate<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dict, TKey key, TValue newValue, out TValue oldValue)
Parameters
dictConcurrentDictionary<TKey, TValue>keyTKeynewValueTValueoldValueTValue
Returns
- bool
Whether or not the value was already in the dictionary.
Type Parameters
TKeyTValue
AddToArray<TElement>(TElement[]?, TElement)
Adds an element to an array and returns the new array.
[MustUseReturnValue]
public static TElement[] AddToArray<TElement>(TElement[]? array, TElement value)
Parameters
arrayTElement[]valueTElement
Returns
- TElement[]
Type Parameters
TElement
AddToArray<TElement>(TElement[]?, TElement, int)
Inserts an element into an array and returns the new array.
[MustUseReturnValue]
public static TElement[] AddToArray<TElement>(TElement[]? array, TElement value, int index)
Parameters
arrayTElement[]valueTElementindexint
Returns
- TElement[]
Type Parameters
TElement
Exceptions
AddToArray<TElement>(ref TElement[], TElement)
Adds an element to an array.
public static void AddToArray<TElement>(ref TElement[] array, TElement value)
Parameters
arrayTElement[]valueTElement
Type Parameters
TElement
AddToArray<TElement>(ref TElement[], TElement, int)
Inserts an element into an array.
public static void AddToArray<TElement>(ref TElement[] array, TElement value, int index)
Parameters
arrayTElement[]valueTElementindexint
Type Parameters
TElement
Exceptions
AsSpan<TElement>(List<TElement>)
Extract a span from a list.
public static ReadOnlySpan<TElement> AsSpan<TElement>(this List<TElement> list)
Parameters
listList<TElement>
Returns
- ReadOnlySpan<TElement>
Type Parameters
TElement
CloneArray<T>(T[], int, int)
Creates a deep copy of an array as an array, using ICloneable to clone all elements.
public static T[] CloneArray<T>(T[] source, int index = 0, int length = -1) where T : ICloneable
Parameters
Returns
- T[]
Type Parameters
T
CloneBytes(byte[], int, int)
Creates a copy of a byte array.
public static byte[] CloneBytes(this byte[] source, int index = 0, int length = -1)
Parameters
Returns
- byte[]
CloneList<T>(IList<T>, int, int)
Creates a shallow copy of a list as an array, using ICloneable to clone all elements.
public static T[] CloneList<T>(IList<T> source, int index = 0, int length = -1) where T : ICloneable
Parameters
Returns
- T[]
Type Parameters
T
CloneReadOnlyList<T>(IReadOnlyList<T>, int, int)
Creates a shallow copy of a list as an array, using ICloneable to clone all elements.
public static T[] CloneReadOnlyList<T>(IReadOnlyList<T> source, int index = 0, int length = -1) where T : ICloneable
Parameters
sourceIReadOnlyList<T>indexintlengthint
Returns
- T[]
Type Parameters
T
CloneReadOnlyStructList<T>(IReadOnlyList<T>, int, int)
Creates a shallow copy of a list as an array.
public static T[] CloneReadOnlyStructList<T>(IReadOnlyList<T> source, int index = 0, int length = -1) where T : struct
Parameters
sourceIReadOnlyList<T>indexintlengthint
Returns
- T[]
Type Parameters
T
CloneStructArray<T>(T[], int, int)
Creates a shallow copy of a list as an array.
public static T[] CloneStructArray<T>(T[] source, int index = 0, int length = -1) where T : struct
Parameters
Returns
- T[]
Type Parameters
T
CloneStructList<T>(IList<T>, int, int)
Creates a shallow copy of a list as an array.
public static T[] CloneStructList<T>(IList<T> source, int index = 0, int length = -1) where T : struct
Parameters
Returns
- T[]
Type Parameters
T
CompareBytes(byte[]?, byte[]?)
Compares two byte arrays.
public static bool CompareBytes(byte[]? arr1, byte[]? arr2)
Parameters
Returns
FindIndexed<TElement>(TElement[], Func<TElement, int, bool>)
Find a value from an array with the index of each element in the predicate.
public static TElement? FindIndexed<TElement>(this TElement[] array, Func<TElement, int, bool> predicate)
Parameters
Returns
- TElement
Type Parameters
TElement
IsNullOrEmpty<T>(ICollection<T>?)
Check if a collection is null or if it has no elements.
public static bool IsNullOrEmpty<T>(this ICollection<T>? collection)
Parameters
collectionICollection<T>
Returns
Type Parameters
T
RemoveFromArray<TElement>(TElement[], int)
Removes an element from an index in the array.
[MustUseReturnValue]
public static TElement[] RemoveFromArray<TElement>(TElement[] array, int index)
Parameters
arrayTElement[]indexint
Returns
- TElement[]
Type Parameters
TElement
Exceptions
RemoveFromArray<TElement>(ref TElement[], int)
Removes an element from an index in the array.
public static void RemoveFromArray<TElement>(ref TElement[] array, int index)
Parameters
arrayTElement[]indexint
Type Parameters
TElement
Exceptions
StringFind<T>(IEnumerable<T>, Func<T, string?>, ReadOnlySpan<char>, bool)
Search through a list for the first object matching searched text.
public static T? StringFind<T>(IEnumerable<T> set, Func<T, string?> selector, ReadOnlySpan<char> input, bool equalsOnly = false)
Parameters
setIEnumerable<T>selectorFunc<T, string>inputReadOnlySpan<char>equalsOnlyboolText must match exactly to be returned.
Returns
- T
Type Parameters
T
StringIndexOf<T>(IReadOnlyList<T>, Func<T, string?>, ReadOnlySpan<char>, bool)
Search through a list for the first index of an object matching searched text.
public static int StringIndexOf<T>(IReadOnlyList<T> collection, Func<T, string?> selector, ReadOnlySpan<char> input, bool equalsOnly = false)
Parameters
collectionIReadOnlyList<T>selectorFunc<T, string>inputReadOnlySpan<char>equalsOnlyboolText must match exactly to be returned.
Returns
Type Parameters
T
StringSearch<T>(IEnumerable<T>, IList<T>, Func<T, string?>, ReadOnlySpan<char>, bool)
Search through a list for all objects matching searched text.
public static int StringSearch<T>(IEnumerable<T> set, IList<T> results, Func<T, string?> selector, ReadOnlySpan<char> input, bool equalsOnly = false)
Parameters
setIEnumerable<T>resultsIList<T>selectorFunc<T, string>inputReadOnlySpan<char>equalsOnlyboolText must match exactly to be returned.
Returns
- int
Number of results.
Type Parameters
T
ToArrayFast<TElement>(IEnumerable<TElement>, bool)
Convert to an array if it isn't already.
public static TElement[] ToArrayFast<TElement>(this IEnumerable<TElement> enumerable, bool copy = false)
Parameters
enumerableIEnumerable<TElement>copybool
Returns
- TElement[]
Type Parameters
TElement