DictionaryHelper Class
Namespace: PTS
Assembly: PTSframework.dll
Provides a set of static methods for IDictionary
type.
Syntax
public static class DictionaryHelper
Inheritance
Methods
InitializeKey<TKey, TValue>(IDictionary<TKey, TValue>, TKey)
Adds default value for specified key.
Declaration
public static TValue InitializeKey<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
where TValue : new()
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary to add the default key value pair to. |
TKey | key | The key to locate a value in the dictionary. |
Returns
Type | Description |
---|---|
TValue | Value assigned to specified key. |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |
InitializeKey<TKey, TValue, TDefaultValue>(IDictionary<TKey, TValue>, TKey)
Adds default value of specified generic type for specified key.
Declaration
public static TValue InitializeKey<TKey, TValue, TDefaultValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
where TDefaultValue : TValue, new()
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary to add the default key value pair to. |
TKey | key | The key to locate a value in the dictionary. |
Returns
Type | Description |
---|---|
TValue | Value assigned to specified key. |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |
TDefaultValue | The type of the default value to be added for unoccupied key. |
ToReadOnly<TKey, TValue>(IDictionary<TKey, TValue>)
Creates a new instance ofReadOnlyDictionary
for given dictionary.
Declaration
public static ReadOnlyDictionary<TKey, TValue> ToReadOnly<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary get read only collection for. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyDictionary<TKey, TValue> | A new instance of |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |
TryGetValue<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, TKey)
Gets the value associated with the specified key if .
Declaration
public static TValue TryGetValue<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> collection, TKey key)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> | collection | |
TKey | key | The key whose value to get. |
Returns
Type | Description |
---|---|
TValue | Matched value if the dictionary contains an element with the specified key; otherwise, |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |