Class DictionarySort<T, U>
- Namespace
- SunamoCollectionsGeneric.Collections
- Assembly
- SunamoCollectionsGeneric.dll
Helper class for sorting dictionaries by keys or values
public class DictionarySort<T, U> where T : notnull
Type Parameters
TThe type of keys
UThe type of values
- Inheritance
-
DictionarySort<T, U>
- Inherited Members
- Extension Methods
Methods
KeyFromValue(Dictionary<T, U>, U)
Finds the first key associated with the specified value
public T KeyFromValue(Dictionary<T, U> dictionary, U searchValue)
Parameters
dictionaryDictionary<T, U>The dictionary to search
searchValueUThe value to find the key for
Returns
- T
The key associated with the search value, or default if not found
KeyFromValue(List<T>, int, Dictionary<T, U>, object)
Finds the key for a specified value, starting from a specific index and excluding already added keys
public T KeyFromValue(List<T> addedKeys, int startIndex, Dictionary<T, U> dictionary, object searchValue)
Parameters
addedKeysList<T>Keys that have already been processed
startIndexintIndex to start searching from
dictionaryDictionary<T, U>The dictionary to search
searchValueobjectThe value to find the key for
Returns
- T
The key associated with the search value, or default if not found
KeyFromValue(int, Dictionary<T, U>, object)
Finds the key for a specified value, starting from a specific index
public T KeyFromValue(int startIndex, Dictionary<T, U> dictionary, object searchValue)
Parameters
startIndexintIndex to start searching from
dictionaryDictionary<T, U>The dictionary to search
searchValueobjectThe value to find the key for
Returns
- T
The key associated with the search value, or default if not found
RemoveWhereIsInValueOnly1Object(Dictionary<T, List<U>>)
Removes entries from the dictionary where the value list contains only one object
public Dictionary<T, List<U>> RemoveWhereIsInValueOnly1Object(Dictionary<T, List<U>> dictionary)
Parameters
dictionaryDictionary<T, List<U>>The dictionary to filter
Returns
- Dictionary<T, List<U>>
A new dictionary containing only entries with more than one value
ReturnKeys(Dictionary<T, U>)
Returns all keys from the dictionary as a list
public List<T> ReturnKeys(Dictionary<T, U> dictionary)
Parameters
dictionaryDictionary<T, U>The dictionary to extract keys from
Returns
- List<T>
A list of all keys in the dictionary
ReturnValues(Dictionary<T, U>)
Returns all values from the dictionary as a list
public List<U> ReturnValues(Dictionary<T, U> dictionary)
Parameters
dictionaryDictionary<T, U>The dictionary to extract values from
Returns
- List<U>
A list of all values in the dictionary
SortByKeysAsc(Dictionary<T, U>)
Sorted z->a, then numbers from largest to smallest, slashes after. Calls reverse.
public Dictionary<T, U> SortByKeysAsc(Dictionary<T, U> dictionary)
Parameters
dictionaryDictionary<T, U>The dictionary to sort.
Returns
- Dictionary<T, U>
A new dictionary sorted by keys in ascending order.
SortByKeysDesc(Dictionary<T, U>)
Sorted a->z, slash first, then numbers, then letters - all standard. Compared without calling Reverse.
public Dictionary<T, U> SortByKeysDesc(Dictionary<T, U> dictionary)
Parameters
dictionaryDictionary<T, U>The dictionary to sort.
Returns
- Dictionary<T, U>
A new dictionary sorted by keys in descending order.
SortByValuesDesc(Dictionary<T, U>)
Sorted a->z, slash first, then numbers, then letters - all standard. Compared without calling Reverse.
public Dictionary<T, U> SortByValuesDesc(Dictionary<T, U> dictionary)
Parameters
dictionaryDictionary<T, U>The dictionary to sort.
Returns
- Dictionary<T, U>
A new dictionary sorted by values in descending order.