Ejemplo n.º 1
0
 public static void SetValue <TType, TKey>(this IDictionary <TKey, object> dictionary, TypedDictionaryKey <TType, TKey> key, TType value, bool clearIfDefault = false)
 {
     if (clearIfDefault && EqualityComparer <TType> .Default.Equals(value, key.DefaultValue))
     {
         dictionary.Remove(key.Key);
     }
     else
     {
         dictionary[key.Key] = value;
     }
 }
Ejemplo n.º 2
0
        public static TType GetValueOrDefault <TType, TKey>(this IDictionary <TKey, object> dictionary, TypedDictionaryKey <TType, TKey> key)
        {
            TType val;

            TryGetValue(dictionary, key, out val);
            return(val);
        }
Ejemplo n.º 3
0
        public static bool TryGetValue <TType, TKey>(this IDictionary <TKey, object> dictionary, TypedDictionaryKey <TType, TKey> key, out TType value)
        {
            object val;

            if (dictionary.TryGetValue(key.Key, out val))
            {
                value = (TType)val;
                return(true);
            }
            else
            {
                value = key.DefaultValue;
                return(false);
            }
        }
Ejemplo n.º 4
0
 public static TType GetValue <TType, TKey>(this IDictionary <TKey, object> dictionary, TypedDictionaryKey <TType, TKey> key)
 {
     return((TType)dictionary[key.Key]);
 }