Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Static class: RT.Util.ExtensionMethods.DictionaryExtensions

Summary

Provides extension methods on dictionaries (Dictionary<TKey, TValue> and IDictionary<TKey, TValue>).

Static methods

void
AddSafe<K, V>(this IDictionary<K, List<V>> dic, K key, V value)
Adds an element to a List<V> stored in the current IDictionary<K, List<V>>. If the specified key does not exist in the current IDictionary, a new List is created.
bool
AddSafe<K, V>(this IDictionary<K, HashSet<V>> dic, K key, V value)
Adds an element to a HashSet<V> stored in the current IDictionary<K, HashSet<V>>. If the specified key does not exist in the current IDictionary, a new HashSet is created.
void
AddSafe<K1, K2, V>(this IDictionary<K1, Dictionary<K2, List<V>>> dic, K1 key1, K2 key2, V value)
Adds an element to a List<V> stored in a two-level Dictionary<,>. If the specified key does not exist in the current Dictionary, a new List is created.
void
AddSafe<K1, K2, V>(this IDictionary<K1, Dictionary<K2, V>> dic, K1 key1, K2 key2, V value, IEqualityComparer<K2> comparer = null)
Adds an element to a two-level Dictionary<,>. If the specified key does not exist in the outer Dictionary, a new Dictionary is created.
bool
Contains<TKey, TValue>(this IDictionary<TKey, HashSet<TValue>> source, TKey key, TValue value)
Determines whether the current HashSet-in-a-Dictionary contains the specified key and value.
bool
ContainsKeys<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> source, TKey1 key1, TKey2 key2)
Determines whether the current two-level dictionary contains the specified combination of keys.
IDictionary<TKey, TValue>
CopyMerge<TKey, TValue>(this IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)
Creates a new dictionary containing the union of the key/value pairs contained in the specified dictionaries. Keys in second overwrite keys in first.
bool
DictionaryEqual<TK, TV>(this IDictionary<TK, TV> dictA, IDictionary<TK, TV> dictB)
Compares two dictionaries for equality, member-wise. Two dictionaries are equal if they contain all the same key-value pairs.
TValue
Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultVal)
Gets a value from a dictionary by key. If the key does not exist in the dictionary, the default value is returned instead.
TValue?
Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue? defaultVal = null)
TValue
Get<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> dict, TKey1 key1, TKey2 key2, TValue defaultVal)
Gets a value from a two-level dictionary by key. If the keys don’t exist in the dictionary, the default value is returned instead.
int
IncSafe<K>(this IDictionary<K, int> dic, K key, int amount = 1)
Increments an integer in an IDictionary<TKey, TValue> by the specified amount. If the specified key does not exist in the current dictionary, the value amount is inserted.
void
RemoveAll<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<KeyValuePair<TKey, TVal>, bool> predicate)
Removes all entries from a dictionary that satisfy a specified predicate.
void
RemoveAllByKey<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<TKey, bool> predicate)
Removes all entries from a dictionary whose keys satisfy a specified predicate.
void
RemoveAllByValue<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<TVal, bool> predicate)
Removes all entries from a dictionary whose values satisfy a specified predicate.
void
RemoveSafe<K, V>(this IDictionary<K, List<V>> dic, K key, V value)
Removes the first occurrence of an element from a List<V> stored in the current IDictionary<K, List<V>>. If this leaves the list stored at the specified key empty, the key is removed from the IDictionary. If the key is not in the dictionary to begin with, nothing happens.
bool
RemoveSafe<K1, K2, V>(this IDictionary<K1, Dictionary<K2, V>> dic, K1 key1, K2 key2)
Removes an element from a two-level Dictionary<,>. If this leaves the inner dictionary empty, the key is removed from the outer Dictionary.
bool
TryGetValue<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> source, TKey1 key1, TKey2 key2, out TValue value)
Gets the value associated with the specified combination of keys.