Class CollectionExtensions
Inheritance
object
CollectionExtensions
Namespace: TetraCreations.Core
Assembly: cs.temp.dll.dll
Syntax
public static class CollectionExtensions
Methods
AddIf<T>(ICollection<T>, T, Func<T, bool>)
Add an element to the collection depending on a predicate function
Declaration
public static bool AddIf<T>(this ICollection<T> collection, T element, Func<T, bool> predicate)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
T |
element |
The element to add
|
Func<, ><T, bool> |
predicate |
Predicate function needs to return true to add the element
|
Returns
Type Parameters
AddIfNotContains<T>(ICollection<T>, T)
Add the T value to the collection if it doesn't already exists inside
Declaration
public static bool AddIfNotContains<T>(this ICollection<T> collection, T value)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
T |
value |
|
Returns
Type Parameters
AddIfNotNull<T>(ICollection<T>, T)
Add the T element to the collection if it's not null
Declaration
public static bool AddIfNotNull<T>(this ICollection<T> collection, T element)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
T |
element |
|
Returns
Type Parameters
AsString<T>(IList<T>, string)
Return the list content as a string
Declaration
public static string AsString<T>(this IList<T> list, string separator = ", ")
Parameters
Type |
Name |
Description |
IList<><T> |
list |
|
string |
separator |
|
Returns
Type Parameters
GetOrDefault<T>(T[], int)
Returns T from the index if it exist otherwise default(T)
Declaration
public static T GetOrDefault<T>(this T[] array, int index)
Parameters
Type |
Name |
Description |
T[] |
array |
|
int |
index |
|
Returns
Type Parameters
GetRandomElement<T>(IList<T>)
Returns a random element from a list.
Sampling with replacement.
Declaration
public static T GetRandomElement<T>(this IList<T> list)
Parameters
Type |
Name |
Description |
IList<><T> |
list |
|
Returns
Type Parameters
HasUniqueElements<T>(ICollection<T>, IEqualityComparer<T>)
Determines if the collection contains only unique elements using a custom IEqualityComparer
Declaration
public static bool HasUniqueElements<T>(this ICollection<T> collection, IEqualityComparer<T> comparer)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
IEqualityComparer<><T> |
comparer |
|
Returns
Type Parameters
HasUniqueElements<T>(ICollection<T>)
Determines if the collection contains only unique elements
Declaration
public static bool HasUniqueElements<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Returns
Type Parameters
IndexInRange<T>(T[], int)
Returns true if the index exist in the array
Declaration
public static bool IndexInRange<T>(this T[] array, int index)
Parameters
Type |
Name |
Description |
T[] |
array |
|
int |
index |
|
Returns
Type Parameters
IsEmpty<T>(ICollection<T>)
Determines if the collection is empty
Declaration
public static bool IsEmpty<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Returns
Type Parameters
IsNotEmpty<T>(ICollection<T>)
Determines if the collection is not empty
Declaration
public static bool IsNotEmpty<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Returns
Type Parameters
IsNotNullOrEmpty<T>(ICollection<T>)
Determines if the collection is not null or empty
Declaration
public static bool IsNotNullOrEmpty<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Returns
Type Parameters
IsNullOrEmpty<T>(ICollection<T>)
Determines if the collection is null or empty
Declaration
public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Returns
Type Parameters
Log<T>(ICollection<T>)
Displays the content of the Collection in the console
Declaration
public static void Log<T>(this ICollection<T> collection)
Parameters
Type |
Name |
Description |
ICollection<><T> |
collection |
|
Type Parameters
LogArray<T>(T[])
Debug.Log all elements from the array
Declaration
public static void LogArray<T>(T[] array)
Parameters
Type |
Name |
Description |
T[] |
array |
|
Type Parameters
RemoveRandomElement<T>(IList<T>)
Removes a random element from a list, returning that item.
Declaration
public static T RemoveRandomElement<T>(this IList<T> list)
Parameters
Type |
Name |
Description |
IList<><T> |
list |
|
Returns
Type Parameters
ReverseLoop<T>(IList<T>)
Loop backwards, useful to delete an element from the list.
Declaration
public static IEnumerable<T> ReverseLoop<T>(this IList<T> list)
Parameters
Type |
Name |
Description |
IList<><T> |
list |
|
Returns
Type |
Description |
IEnumerable<><T> |
|
Type Parameters
Shuffle<T>(IList<T>)
Declaration
public static void Shuffle<T>(this IList<T> list)
Parameters
Type |
Name |
Description |
IList<><T> |
list |
The list to Shuffle
|
Type Parameters
WithoutDuplicates<T>(ICollection<T>)
Declaration
public static List<T> WithoutDuplicates<T>(this ICollection<T> list)
Parameters
Type |
Name |
Description |
ICollection<><T> |
list |
|
Returns
Type |
Description |
List<><T> |
|
Type Parameters