Exemplo n.º 1
0
 public bool Equals(ComparableDictionary <TKey, TValue> other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (Count != other.Count)
     {
         return(false);
     }
     foreach (var pair in this)
     {
         var otherValue;
         if (!other.TryGetValue(pair.Key, out otherValue))
         {
             return(false);
         }
         if (!EqualityComparer <TValue> .Default.Equals(pair.Value,
                                                        otherValue))
         {
             return(false);
         }
     }
     return(true);
 }
        /// <summary>
        /// Creates dictionary instance from KeyValuePair entries.
        /// </summary>
        /// <typeparam name="T">Type of key</typeparam>
        /// <typeparam name="TV">Type of value</typeparam>
        /// <param name="entries">entries</param>
        /// <returns>dictionary</returns>
        public static IDictionary <T, TV> CreateFromEntries <T, TV>(params KeyValuePair <T, TV>[] entries)
        {
            var dictionary = new Dictionary <T, TV>(entries.Length);

            dictionary.PutAll(entries);
            return(ComparableDictionary <T, TV> .Of(dictionary));
        }
        public override void Initialize()
        {
            base.Initialize();

            var groups = ServerModel.DB.Query<TblGroups>(null);
            var list = new ComparableDictionary<int, string> { { -1, "<new>" } };
            foreach (var g in groups)
            {
                list.Add(g.ID, g.Name);
            }

            Groups.Value = list;
        }
        public override void Initialize()
        {
            base.Initialize();

            var groups = ServerModel.DB.Query <TblGroups>(null);
            var list   = new ComparableDictionary <int, string> {
                { -1, "<new>" }
            };

            foreach (var g in groups)
            {
                list.Add(g.ID, g.Name);
            }

            Groups.Value = list;
        }
        /// <summary>
        /// Maps collection items to number of occurrences.
        /// </summary>
        /// <typeparam name="T">Type of collection item</typeparam>
        /// <param name="source">this</param>
        /// <returns>Dictionary (item, itemCount)</returns>
        public static IDictionary <T, int> DistinctElementCount <T>(this IEnumerable <T> source)
        {
            Preconditions.IsNotNull(source, () => new ArgumentNullException("source"));
            var result = new Dictionary <T, int>();

            foreach (var element in source)
            {
                if (result.ContainsKey(element))
                {
                    result[element] = result[element] + 1;
                }
                else
                {
                    result[element] = 1;
                }
            }
            return(ComparableDictionary <T, int> .Of(result));
        }
 /// <summary>
 /// Converts dictionary into comparable dictionary with equals/hashCode/toString implementations.
 /// </summary>
 /// <typeparam name="TKey">Type of dictionary key</typeparam>
 /// <typeparam name="TValue">Type of dictionary value</typeparam>
 /// <param name="source">this</param>
 /// <returns>Comparable dictionary</returns>
 public static IDictionary <TKey, TValue> ToComparable <TKey, TValue>(this IDictionary <TKey, TValue> source)
 {
     Preconditions.IsNotNull(source, () => new ArgumentNullException("source"));
     return(ComparableDictionary <TKey, TValue> .Of(source));
 }
Exemplo n.º 7
0
 public bool Equals(ComparableDictionary other)
 {
     return other != null && (GetHashCode() == other.GetHashCode());
 }