Exemple #1
0
 /// <summary>
 /// Null safe and self-normalizing indexer
 /// </summary>
 /// <param name="key">Item to get/set based on key index match</param>
 /// <returns>Get returns item from list, or not found will return new instantiation. Set will add/update match by key.</returns>
 public KeyValuePairSafe <TKey, TValue> this[TKey key]
 {
     get
     {
         KeyValuePairSafe <TKey, TValue> returnValue
             = base.Find(x => x.Key.ToStringSafe() == key.ToStringSafe()).CastSafe <KeyValuePairSafe <TKey, TValue> >();
         return(returnValue);
     }
     set
     {
         Add(value);
     }
 }
Exemple #2
0
 /// <summary>
 /// Equality comparison of child key and value combination
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public override bool Equals(KeyValuePairSafe <TKey, TValue> x, KeyValuePairSafe <TKey, TValue> y)
 {
     return(x.ToStringSafe() == y.Key.ToStringSafe() && x.ToStringSafe() == y.Value.ToStringSafe());
 }
Exemple #3
0
        /// <summary>
        /// Immutable calculated hash code based on (Key.GetHashCode() * 17) + (Value.GetHashCode())
        /// </summary>
        /// <param name="obj">Object to compare, must be of type KeyValuePairSafe</param>
        /// <returns></returns>
        public override int GetHashCode(KeyValuePairSafe <TKey, TValue> obj)
        {
            KeyValuePairSafe <TKey, TValue> item = obj ?? new KeyValuePairSafe <TKey, TValue>();

            return(item.Key.GetHashCode() * 17 + item.Value.GetHashCode());
        }
Exemple #4
0
 /// <summary>
 /// Default comparer
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(KeyValuePairSafe <TKey, TValue> other)
 {
     return(Key.ToStringSafe() == other.Key.ToStringSafe() && Value.ToStringSafe() == other.Value.ToStringSafe());
 }