示例#1
0
文件: MultiSet.cs 项目: bladepan/Nier
        /// <summary>
        /// set the item count
        /// </summary>
        /// <param name="item"></param>
        /// <param name="newCountFunc">current item count to new count value</param>
        /// <returns></returns>
        private int SetItemCount(TValue item, Func <int, int> newCountFunc)
        {
            int newItemCount;
            int oldItemCount;

            NullableKey <TValue> key = new NullableKey <TValue>(item);

            if (_values.TryGetValue(key, out int currentItemCount))
            {
                oldItemCount = currentItemCount;
                newItemCount = newCountFunc(currentItemCount);
            }
            else
            {
                oldItemCount = 0;
                newItemCount = newCountFunc(0);
            }

            if (oldItemCount != newItemCount)
            {
                if (newItemCount == 0)
                {
                    _values.Remove(key);
                }
                else
                {
                    _values[key] = newItemCount;
                }

                Count = Count - oldItemCount + newItemCount;
            }

            return(oldItemCount);
        }
示例#2
0
文件: MultiSet.cs 项目: bladepan/Nier
 public bool Equals(NullableKey <TKey> other) => Equals(Key, other.Key);