예제 #1
0
        /// <summary>
        /// Removes the value if the the key exists.
        /// </summary>
        /// <typeparam name="TKey">The type of the key in the key value table.</typeparam>
        /// <typeparam name="TValue">The type of the value in the key value table.</typeparam>
        /// <param name="table">The key value table.</param>
        /// <param name="key">The key to remove.</param>
        /// <returns>True if found, false otherwise.</returns>
        public static bool TryRemove <TKey, TValue>(this ITransactedKeyValueTable <TKey, TValue> table, TKey key)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (table.Contains(key))
            {
                table.Remove(key);
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Gets the value if the the key exists.
        /// </summary>
        /// <typeparam name="TKey">The type of the key in the key value table.</typeparam>
        /// <typeparam name="TValue">The type of the value in the key value table.</typeparam>
        /// <param name="table">The key value table.</param>
        /// <param name="key">The key to lookup.</param>
        /// <param name="value">The value corresponding to the key.</param>
        /// <returns>True if found, false otherwise.</returns>
        public static bool TryGet <TKey, TValue>(this ITransactedKeyValueTable <TKey, TValue> table, TKey key, out TValue value)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (table.Contains(key))
            {
                value = table[key];
                return(true);
            }

            value = default;
            return(false);
        }
 public bool Contains(string key) => _table.Contains(key);