Table of Contents

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

string

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

list List<T>

The list to add to

element T

The element to add

Type Parameters

T

The 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

firstList List<string>

The first list to compare

secondList List<string>

The second list to compare

typeScriptHelperGetNamesAndTypes Func<List<string>, Tuple<List<string>, List<string>>>

Optional TypeScript helper function for parsing interfaces

isTsInterface bool

Whether 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

firstList List<T>

The first list to compare.

secondList List<T>

The second list to compare.

Returns

List<T>

A list of elements that exist in both input lists.

Type Parameters

T

The 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

value T

The value to count

items T[]

The items to search in

Returns

int

The number of occurrences of the value

Type Parameters

T

The 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

element T

The element to insert

Returns

List<T>

A list containing the single element

Type Parameters

T

The 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

list List<T>

The list to search in.

searchPattern List<T>

The pattern to search for.

Returns

List<FromToCollectionsGenericShared>

List of ranges where the pattern was found.

Type Parameters

T

The 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

rows T[,]

The two-dimensional array.

columnIndex int

The index of the column to extract.

Returns

List<T>

A list containing all elements from the specified column.

Type Parameters

T

The 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

list List<T>

The list to search for duplicates.

Returns

List<T>

A list of duplicated items, each appearing once.

Type Parameters

T

The 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

list List<T>

The list to search for duplicates.

alreadyProcessed List<T>

Output list of all unique items encountered.

Returns

List<T>

A list of duplicated items, each appearing once.

Type Parameters

T

The 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

list IList<T>

The list to get element from

index int

The index to retrieve

Returns

T

The element at index or the previous element, or default if not found

Type Parameters

T

The 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

index int

The index to retrieve

list IList<T>

The list to get element from

listName string

Optional name of the list for error messages

returnWhenIndexNotExists T

Optional value to return instead of throwing exception

Returns

T

The element at the specified index

Type Parameters

T

The 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

rows T[,]

The two-dimensional array.

rowIndex int

The index of the row to extract.

Returns

List<T>

A list containing all elements from the specified row.

Type Parameters

T

The 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

element T

The element to compare against

list IList<T>

The list to check

Returns

bool

True if all elements are equal to the specified element, false otherwise

Type Parameters

T

The 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

element T

The element to search for

list IList<T>

The list to search in

Returns

bool

True if element is found in the list, false otherwise

Type Parameters

T

The 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

element T

The element to search for

items T[]

The items to search in

Returns

bool

True if element is found in items, false otherwise

Type Parameters

T

The 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

lists List<List<T>>

The list of lists to examine

Returns

int

The count of the smallest inner list

Type Parameters

T

The 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

lists List<List<T>>

The list of lists to examine

Returns

int

The count of the largest inner list

Type Parameters

T

The 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

lists List<List<T>>

The list of lists to examine

Returns

int

The count of the smallest inner list

Type Parameters

T

The 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

list List<T>

The list to check

zeroOrMore bool?

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

T

The 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

flatArray T[]

The one-dimensional array to convert

width int

The width of the resulting two-dimensional array

Returns

T[,]

A two-dimensional array

Type Parameters

T

The type of elements

RemoveDuplicitiesList<T>(IList<T>)

Removes duplicates from the list (direct edit)

public static List<T> RemoveDuplicitiesList<T>(IList<T> list)

Parameters

list IList<T>

The list to remove duplicates from

Returns

List<T>

List of unique items

Type Parameters

T

The 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

list IList<T>

The list to remove duplicates from.

foundDuplicates List<T>

Output list of all duplicate items found.

Returns

List<T>

A list of unique items.

Type Parameters

T

The type of elements.

ToArrayT<T>(params T[])

Converts variable arguments to an array

public static T[] ToArrayT<T>(params T[] array)

Parameters

array T[]

The items to convert to an array

Returns

T[]

An array containing the provided items

Type Parameters

T

The 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

array T[,]

The two-dimensional array to convert.

Returns

T[][]

A jagged array representation of the input.

Type Parameters

T

The 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

array T[]

The items to convert to a list.

Returns

List<T>

A list containing the provided items.

Type Parameters

T

The 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

lists List<List<T>>

The list of lists to trim

targetCount int

The maximum number of elements to keep in each inner list

Returns

List<List<T>>

The modified list with trimmed inner lists

Type Parameters

T

The type of elements