Class CAG
- Namespace
- SunamoCollectionsGeneric
- Assembly
- SunamoCollectionsGeneric.dll
Collection helper class providing utility methods for working with generic collections
public class CAG
- Inheritance
-
CAG
- Inherited Members
- Extension Methods
Fields
XInvalidRowIndexInMethodCAGetRowOfTwoDimensionalArray
Error message for invalid row index in GetRowOfTwoDimensionalArray method
public const string XInvalidRowIndexInMethodCAGetRowOfTwoDimensionalArray = "InvalidRowIndexInMethodCAGetRowOfTwoDimensionalArray"
Field Value
Methods
AddIfNotContains<T>(List<T>, T)
Adds an element to the list only if it doesn't already contain it
public static void AddIfNotContains<T>(List<T> list, T element)
Parameters
listList<T>The list to add to
elementTThe element to add
Type Parameters
TThe type of elements
CompareListSanitizeStringOutput(List<string>, List<string>, Func<List<string>, Tuple<List<string>, List<string>>>?, bool)
Compares two lists and returns a formatted string showing differences and common elements
public static string CompareListSanitizeStringOutput(List<string> firstList, List<string> secondList, Func<List<string>, Tuple<List<string>, List<string>>>? typeScriptHelperGetNamesAndTypes = null, bool isTsInterface = false)
Parameters
firstListList<string>The first list to compare
secondListList<string>The second list to compare
typeScriptHelperGetNamesAndTypesFunc<List<string>, Tuple<List<string>, List<string>>>Optional TypeScript helper function for parsing interfaces
isTsInterfaceboolWhether the lists contain TypeScript interface definitions
Returns
- string
A formatted string showing elements only in first list, only in second list, and in both
CompareList<T>(List<T>, List<T>)
Returns elements that exist in both lists. Modifies both input lists to keep only elements unique to each.
public static List<T> CompareList<T>(List<T> firstList, List<T> secondList) where T : IEquatable<T>
Parameters
Returns
- List<T>
A list of elements that exist in both input lists.
Type Parameters
TThe type of elements.
CountOfValue<T>(T, params T[])
Counts how many times a specific value appears in the provided items
public static int CountOfValue<T>(T value, params T[] items)
Parameters
valueTThe value to count
itemsT[]The items to search in
Returns
- int
The number of occurrences of the value
Type Parameters
TThe type of elements
CreateListAndInsertElement<T>(T)
Creates a new list and inserts the specified element into it
public static List<T> CreateListAndInsertElement<T>(T element)
Parameters
elementTThe element to insert
Returns
- List<T>
A list containing the single element
Type Parameters
TThe type of element
EqualRanges<T>(List<T>, List<T>)
Returns equal ranges in the list that match the search pattern.
public static List<FromToCollectionsGenericShared> EqualRanges<T>(List<T> list, List<T> searchPattern)
Parameters
Returns
- List<FromToCollectionsGenericShared>
List of ranges where the pattern was found.
Type Parameters
TThe type of elements.
GetColumnOfTwoDimensionalArray<T>(T[,], int)
In the first index are rows, in the second are columns.
public static List<T> GetColumnOfTwoDimensionalArray<T>(T[,] rows, int columnIndex)
Parameters
rowsT[,]The two-dimensional array.
columnIndexintThe index of the column to extract.
Returns
- List<T>
A list containing all elements from the specified column.
Type Parameters
TThe type of elements in the array.
GetDuplicities<T>(List<T>)
Gets every duplicated item once.
public static List<T> GetDuplicities<T>(List<T> list)
Parameters
listList<T>The list to search for duplicates.
Returns
- List<T>
A list of duplicated items, each appearing once.
Type Parameters
TThe type of elements.
GetDuplicities<T>(List<T>, out List<T>)
Gets every duplicated item once. More duplicates in the list result in more items in the output.
public static List<T> GetDuplicities<T>(List<T> list, out List<T> alreadyProcessed)
Parameters
listList<T>The list to search for duplicates.
alreadyProcessedList<T>Output list of all unique items encountered.
Returns
- List<T>
A list of duplicated items, each appearing once.
Type Parameters
TThe type of elements.
GetElementActualOrBefore<T>(IList<T>, int)
Gets the element at the specified index, or the element before it if index is out of bounds
public static T GetElementActualOrBefore<T>(IList<T> list, int index)
Parameters
Returns
- T
The element at index or the previous element, or default if not found
Type Parameters
TThe type of elements
GetIndexOrBreak<T>(int, IList<T>, string, T?)
Gets the element at the specified index, breaking into debugger or throwing exception if index is out of bounds
public static T GetIndexOrBreak<T>(int index, IList<T> list, string listName = "", T? returnWhenIndexNotExists = default)
Parameters
indexintThe index to retrieve
listIList<T>The list to get element from
listNamestringOptional name of the list for error messages
returnWhenIndexNotExistsTOptional value to return instead of throwing exception
Returns
- T
The element at the specified index
Type Parameters
TThe type of elements
GetRowOfTwoDimensionalArray<T>(T[,], int)
In the first index are rows, in the second are columns.
public static List<T> GetRowOfTwoDimensionalArray<T>(T[,] rows, int rowIndex)
Parameters
rowsT[,]The two-dimensional array.
rowIndexintThe index of the row to extract.
Returns
- List<T>
A list containing all elements from the specified row.
Type Parameters
TThe type of elements in the array.
IsAllTheSame<T>(T, IList<T>)
Checks if all elements in the list are equal to the specified element
public static bool IsAllTheSame<T>(T element, IList<T> list)
Parameters
elementTThe element to compare against
listIList<T>The list to check
Returns
- bool
True if all elements are equal to the specified element, false otherwise
Type Parameters
TThe type of elements
IsEqualToAnyElement<T>(T, IList<T>)
Checks if the specified element is equal to any element in the list
public static bool IsEqualToAnyElement<T>(T element, IList<T> list)
Parameters
elementTThe element to search for
listIList<T>The list to search in
Returns
- bool
True if element is found in the list, false otherwise
Type Parameters
TThe type of elements
IsEqualToAnyElement<T>(T, params T[])
Checks if the specified element is equal to any of the provided items
public static bool IsEqualToAnyElement<T>(T element, params T[] items)
Parameters
elementTThe element to search for
itemsT[]The items to search in
Returns
- bool
True if element is found in items, false otherwise
Type Parameters
TThe type of elements
LowestCount<T>(List<List<T>>)
Finds the lowest count among all inner lists
public static int LowestCount<T>(List<List<T>> lists)
Parameters
Returns
- int
The count of the smallest inner list
Type Parameters
TThe type of elements
MaxElementsItemsInnerList<T>(List<List<T>>)
Finds the maximum number of elements among all inner lists
public static int MaxElementsItemsInnerList<T>(List<List<T>> lists)
Parameters
Returns
- int
The count of the largest inner list
Type Parameters
TThe type of elements
MinElementsItemsInnerList<T>(List<List<T>>)
Finds the minimum number of elements among all inner lists
public static int MinElementsItemsInnerList<T>(List<List<T>> lists)
Parameters
Returns
- int
The count of the smallest inner list
Type Parameters
TThe type of elements
MoreOrZero<T>(List<T>, out bool?)
Checks if the list has zero or more than one element
public static bool MoreOrZero<T>(List<T> list, out bool? zeroOrMore)
Parameters
listList<T>The list to check
zeroOrMorebool?True if list is empty, false if list has more than one element, null if list has exactly one element
Returns
- bool
True if list is empty or has more than one element, false if list has exactly one element
Type Parameters
TThe type of elements
OneDimensionArrayToTwoDirection<T>(T[], int)
Converts a one-dimensional array to a two-dimensional array with the specified width
public static T[,] OneDimensionArrayToTwoDirection<T>(T[] flatArray, int width)
Parameters
flatArrayT[]The one-dimensional array to convert
widthintThe width of the resulting two-dimensional array
Returns
- T[,]
A two-dimensional array
Type Parameters
TThe type of elements
RemoveDuplicitiesList<T>(IList<T>)
Removes duplicates from the list (direct edit)
public static List<T> RemoveDuplicitiesList<T>(IList<T> list)
Parameters
listIList<T>The list to remove duplicates from
Returns
- List<T>
List of unique items
Type Parameters
TThe type of elements
RemoveDuplicitiesList<T>(IList<T>, out List<T>)
Removes duplicates from the list (direct edit). Returns a list of unique items. The out parameter contains every duplicate (possibly repeated).
public static List<T> RemoveDuplicitiesList<T>(IList<T> list, out List<T> foundDuplicates)
Parameters
listIList<T>The list to remove duplicates from.
foundDuplicatesList<T>Output list of all duplicate items found.
Returns
- List<T>
A list of unique items.
Type Parameters
TThe type of elements.
ToArrayT<T>(params T[])
Converts variable arguments to an array
public static T[] ToArrayT<T>(params T[] array)
Parameters
arrayT[]The items to convert to an array
Returns
- T[]
An array containing the provided items
Type Parameters
TThe type of elements
ToJagged<T>(T[,])
Converts a two-dimensional array to a jagged array (array of arrays). Changes from an array where every element has two specifications of location to an ordinary array with inner arrays.
public static T[][] ToJagged<T>(T[,] array)
Parameters
arrayT[,]The two-dimensional array to convert.
Returns
- T[][]
A jagged array representation of the input.
Type Parameters
TThe type of elements in the array.
ToList<T>(params T[])
Converts a variable number of parameters into a list. This could also be named ToListObject because it doesn't take or return a specific type (e.g., string) but a generic type.
public static List<T> ToList<T>(params T[] array)
Parameters
arrayT[]The items to convert to a list.
Returns
- List<T>
A list containing the provided items.
Type Parameters
TThe type of elements.
TrimInnersToCount<T>(List<List<T>>, int)
Trims all inner lists to the specified count by taking only the first targetCount elements
public static List<List<T>> TrimInnersToCount<T>(List<List<T>> lists, int targetCount)
Parameters
listsList<List<T>>The list of lists to trim
targetCountintThe maximum number of elements to keep in each inner list
Returns
Type Parameters
TThe type of elements