コード例 #1
0
        static public IReadOnlyDictionary <TKey, TValue> AddOrUpdateWithTransform <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> _this, TKey key, TValue value, Func <TValue, TValue> oxTransform, IEqualityComparer <TKey> comparer)
            where TKey : struct
        {
            var res = _this.Get(key, comparer);

            if (!res.Exists)
            {
                return(_this.AddOrUpdate(key, value, comparer));
            }
            else
            {
                var newVal = oxTransform(res.Value);

                return(_this.AddOrUpdate(key, newVal, comparer));
            }
        }
コード例 #2
0
        static public IReadOnlyDictionary <TKey, TValue> AddOrUpdateIf <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> _this, TKey key, TValue value, Predicate <TValue> oxUpdateIf, IEqualityComparer <TKey> keyComparer)
            where TKey : struct
        {
            var res = _this.Get(key, keyComparer);

            if (!res.Exists)
            {
                return(_this.AddOrUpdate(key, value, keyComparer));
            }
            else
            {
                if (!oxUpdateIf(res.Value))
                {
                    return(_this);
                }
                else
                {
                    return(_this.AddOrUpdate(key, value, keyComparer));
                }
            }
        }