Table of Contents

Class CollectionUtility

Namespace
Uncreated.Warfare.Util
Assembly
Uncreated.Warfare.dll
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

dict ConcurrentDictionary<TKey, TValue>
key TKey
newValue TValue
oldValue TValue

Returns

bool

Whether or not the value was already in the dictionary.

Type Parameters

TKey
TValue

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

array TElement[]
value TElement

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

array TElement[]
value TElement
index int

Returns

TElement[]

Type Parameters

TElement

Exceptions

ArgumentOutOfRangeException

AddToArray<TElement>(ref TElement[], TElement)

Adds an element to an array.

public static void AddToArray<TElement>(ref TElement[] array, TElement value)

Parameters

array TElement[]
value TElement

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

array TElement[]
value TElement
index int

Type Parameters

TElement

Exceptions

ArgumentOutOfRangeException

AsSpan<TElement>(List<TElement>)

Extract a span from a list.

public static ReadOnlySpan<TElement> AsSpan<TElement>(this List<TElement> list)

Parameters

list List<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

source T[]
index int
length int

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

source byte[]
index int
length int

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

source IList<T>
index int
length int

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

source IReadOnlyList<T>
index int
length int

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

source IReadOnlyList<T>
index int
length int

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

source T[]
index int
length int

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

source IList<T>
index int
length int

Returns

T[]

Type Parameters

T

CompareBytes(byte[]?, byte[]?)

Compares two byte arrays.

public static bool CompareBytes(byte[]? arr1, byte[]? arr2)

Parameters

arr1 byte[]
arr2 byte[]

Returns

bool

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

array TElement[]
predicate Func<TElement, int, bool>

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

collection ICollection<T>

Returns

bool

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

array TElement[]
index int

Returns

TElement[]

Type Parameters

TElement

Exceptions

ArgumentNullException
ArgumentOutOfRangeException

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

array TElement[]
index int

Type Parameters

TElement

Exceptions

ArgumentNullException
ArgumentOutOfRangeException

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

set IEnumerable<T>
selector Func<T, string>
input ReadOnlySpan<char>
equalsOnly bool

Text 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

collection IReadOnlyList<T>
selector Func<T, string>
input ReadOnlySpan<char>
equalsOnly bool

Text must match exactly to be returned.

Returns

int

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

set IEnumerable<T>
results IList<T>
selector Func<T, string>
input ReadOnlySpan<char>
equalsOnly bool

Text 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

enumerable IEnumerable<TElement>
copy bool

Returns

TElement[]

Type Parameters

TElement