View Source
  Class DictionaryExtensions
  
  Extension methods for Dictionary & ConcurrentDictionary.
    Inheritance
      System.Object
      
   
  
  Assembly: Umbraco.Core.dll
  Syntax
  
    public static class DictionaryExtensions
   
  Methods
  
  
    View Source
  
  ContainsKeyIgnoreCase<TValue>(IDictionary<String, TValue>, String)
  contains key ignore case.
Declaration
  
    public static bool ContainsKeyIgnoreCase<TValue>(this IDictionary<string, TValue> dictionary, string key)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<System.String, TValue> | dictionary | The dictionary. | 
      
        | System.String | key | The key. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean | The contains key ignore case. | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TValue | Value Type | 
    
  
  
    View Source
  
  ConvertTo<TKeyOut, TValOut>(IDictionary)
  Converts a dictionary to another type by only using direct casting
Declaration
  
    public static IDictionary<TKeyOut, TValOut> ConvertTo<TKeyOut, TValOut>(this IDictionary d)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary | d |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.IDictionary<TKeyOut, TValOut> |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKeyOut |  | 
      
        | TValOut |  | 
    
  
  
    View Source
  
  ConvertTo<TKeyOut, TValOut>(IDictionary, Func<Object, TKeyOut>, Func<Object, TValOut>)
  Converts a dictionary to another type using the specified converters
Declaration
  
    public static IDictionary<TKeyOut, TValOut> ConvertTo<TKeyOut, TValOut>(this IDictionary d, Func<object, TKeyOut> keyConverter, Func<object, TValOut> valConverter)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary | d |  | 
      
        | Func<System.Object, TKeyOut> | keyConverter |  | 
      
        | Func<System.Object, TValOut> | valConverter |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.IDictionary<TKeyOut, TValOut> |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKeyOut |  | 
      
        | TValOut |  | 
    
  
  
    View Source
  
  GetOrCreate<TKey, TVal>(IDictionary<TKey, TVal>, TKey)
  Method to Get a value by the key. If the key doesn't exist it will create a new TVal object for the key and return
it.
Declaration
  
    public static TVal GetOrCreate<TKey, TVal>(this IDictionary<TKey, TVal> dict, TKey key)
    where TVal : class, new()
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<TKey, TVal> | dict |  | 
      
        | TKey | key |  | 
    
  
  Returns
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey |  | 
      
        | TVal |  | 
    
  
  
    View Source
  
  GetValue<TKey, TVal>(IDictionary<TKey, TVal>, TKey, TVal)
  Returns the value of the key value based on the key, if the key is not found, a null value is returned
Declaration
  
    public static TVal GetValue<TKey, TVal>(this IDictionary<TKey, TVal> d, TKey key, TVal defaultValue = null)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<TKey, TVal> | d | The d. | 
      
        | TKey | key | The key. | 
      
        | TVal | defaultValue | The default value. | 
    
  
  Returns
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey | The type of the key. | 
      
        | TVal | The type of the val. | 
    
  
  
    View Source
  
  GetValueAsString<TKey, TVal>(IDictionary<TKey, TVal>, TKey)
  Returns the value of the key value based on the key as it's string value, if the key is not found, then an empty
string is returned
Declaration
  
    public static string GetValueAsString<TKey, TVal>(this IDictionary<TKey, TVal> d, TKey key)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<TKey, TVal> | d |  | 
      
        | TKey | key |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey |  | 
      
        | TVal |  | 
    
  
  
    View Source
  
  GetValueAsString<TKey, TVal>(IDictionary<TKey, TVal>, TKey, String)
  Returns the value of the key value based on the key as it's string value, if the key is not found or is an empty
string, then the provided default value is returned
Declaration
  
    public static string GetValueAsString<TKey, TVal>(this IDictionary<TKey, TVal> d, TKey key, string defaultValue)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<TKey, TVal> | d |  | 
      
        | TKey | key |  | 
      
        | System.String | defaultValue |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey |  | 
      
        | TVal |  | 
    
  
  
    View Source
  
  GetValueIgnoreCase<TValue>(IDictionary<String, TValue>, String)
  The get entry ignore case.
Declaration
  
    public static TValue GetValueIgnoreCase<TValue>(this IDictionary<string, TValue> dictionary, string key)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<System.String, TValue> | dictionary | The dictionary. | 
      
        | System.String | key | The key. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TValue | The entry | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TValue | The type | 
    
  
  
    View Source
  
  GetValueIgnoreCase<TValue>(IDictionary<String, TValue>, String, TValue)
  The get entry ignore case.
Declaration
  
    public static TValue GetValueIgnoreCase<TValue>(this IDictionary<string, TValue> dictionary, string key, TValue defaultValue)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<System.String, TValue> | dictionary | The dictionary. | 
      
        | System.String | key | The key. | 
      
        | TValue | defaultValue | The default value. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TValue | The entry | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TValue | The type | 
    
  
  
    View Source
  
  MergeLeft<T, TK, TV>(T, IDictionary<TK, TV>, Boolean)
  Merges all key/values from the sources dictionaries into the destination dictionary
Declaration
  
    public static void MergeLeft<T, TK, TV>(this T destination, IDictionary<TK, TV> source, bool overwrite = false)
    where T : IDictionary<TK, TV>
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | T | destination | The source dictionary to merge other dictionaries into | 
      
        | System.Collections.IDictionary<TK, TV> | source | The other dictionary to merge values from | 
      
        | System.Boolean | overwrite | By default all values will be retained in the destination if the same keys exist in the sources but
this can changed if overwrite = true, then any key/value found in any of the sources will overwritten in the
destination. Note that
it will just use the last found key/value if this is true. | 
    
  
  Type Parameters
  
  
    View Source
  
  MergeLeft<T, TK, TV>(T, IEnumerable<IDictionary<TK, TV>>, Boolean)
  Merges all key/values from the sources dictionaries into the destination dictionary
Declaration
  
    public static void MergeLeft<T, TK, TV>(this T destination, IEnumerable<IDictionary<TK, TV>> sources, bool overwrite = false)
    where T : IDictionary<TK, TV>
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | T | destination | The source dictionary to merge other dictionaries into | 
      
        | System.Collections.IEnumerable<System.Collections.IDictionary<TK, TV>> | sources | The other dictionaries to merge values from | 
      
        | System.Boolean | overwrite | By default all values will be retained in the destination if the same keys exist in the sources but
this can changed if overwrite = true, then any key/value found in any of the sources will overwritten in the
destination. Note that
it will just use the last found key/value if this is true. | 
    
  
  Type Parameters
  
  
    View Source
  
  ToDictionaryAsync<TInput, TKey, TValue>(IEnumerable<TInput>, Func<TInput, TKey>, Func<TInput, Task<TValue>>)
  
  
  Declaration
  
    public static async Task<Dictionary<TKey, TValue>> ToDictionaryAsync<TInput, TKey, TValue>(this IEnumerable<TInput> enumerable, Func<TInput, TKey> syncKeySelector, Func<TInput, Task<TValue>> asyncValueSelector)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IEnumerable<TInput> | enumerable |  | 
      
        | Func<TInput, TKey> | syncKeySelector |  | 
      
        | Func<TInput, Task<TValue>> | asyncValueSelector |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | Task<Dictionary<TKey, TValue>> |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TInput |  | 
      
        | TKey |  | 
      
        | TValue |  | 
    
  
  
    View Source
  
  ToNameValueCollection(IDictionary<String, String>)
  Converts a dictionary to a NameValueCollection
Declaration
  
    public static NameValueCollection ToNameValueCollection(this IDictionary<string, string> d)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<System.String, System.String> | d |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.Specialized.NameValueCollection |  | 
    
  
  
    View Source
  
  ToQueryString(IDictionary<String, Object>)
  Converts a dictionary object to a query string representation such as:
firstname=shannon&lastname=deminick.
Declaration
  
    public static string ToQueryString(this IDictionary<string, object> d)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.IDictionary<System.String, System.Object> | d |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  
    View Source
  
  TryUpdate<TKey, TValue>(ConcurrentDictionary<TKey, TValue>, TKey, Func<TValue, TValue>)
  Updates an item with the specified key with the specified value
Declaration
  
    public static bool TryUpdate<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dict, TKey key, Func<TValue, TValue> updateFactory)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> | dict |  | 
      
        | TKey | key |  | 
      
        | Func<TValue, TValue> | updateFactory |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey |  | 
      
        | TValue |  | 
    
  
  
  
  
    View Source
  
  TryUpdateOptimisitic<TKey, TValue>(ConcurrentDictionary<TKey, TValue>, TKey, Func<TValue, TValue>)
  Updates an item with the specified key with the specified value
Declaration
  
    public static bool TryUpdateOptimisitic<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dict, TKey key, Func<TValue, TValue> updateFactory)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> | dict |  | 
      
        | TKey | key |  | 
      
        | Func<TValue, TValue> | updateFactory |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TKey |  | 
      
        | TValue |  |