/// <summary> /// Unsets the given key and its value. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key</param> /// <returns><c>true</c> if the key and value was set and removed, otherwise <c>false</c></returns> public virtual bool Unset <T>(ConfigurationKey <T> key) { if (key == null) { throw new ArgumentException("key cannot be null!"); } return(this.configMap.Remove(key)); }
/// <summary> /// Returns <c>true</c> if there is a value set with the given key, otherwise <c>false</c>. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <returns><c>true</c> if there is a value set with the given key, otherwise <c>false</c></returns> public virtual bool Has <T>(ConfigurationKey <T> key) { if (key == null) { throw new ArgumentException("key cannot be null!"); } return(this.configMap.ContainsKey(key)); }
/// <summary> /// Returns <c>true</c> if there is a value set with the given key, otherwise <c>false</c>. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <returns><c>true</c> if there is a value set with the given key, otherwise <c>false</c></returns> public virtual bool Has <T>(ConfigurationKey <T> key) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) } return(this.configMap.ContainsKey(key)); }
/// <summary> /// Returns the value held by the given key. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <returns>the value held by the given key</returns> public virtual T Get <T>(ConfigurationKey <T> key) { if (key == null) { throw new ArgumentException("key cannot be null!"); } this.configMap.TryGetValue(key, out object result); return(result == null ? default : (T)result); }
/// <summary> /// Returns the value held by the given key. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <returns>the value held by the given key</returns> public virtual T Get <T>(ConfigurationKey <T> key) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) } this.configMap.TryGetValue(key, out object result); return(result == null ? default : (T)result); }
/// <summary> /// Returns the value held by the given key. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <returns>the value held by the given key</returns> public virtual T Get <T>(ConfigurationKey <T> key) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) } return(!this.configMap.TryGetValue(key, out object result) || result is null ? default : // LUCENENET: Retrieve a 1 dimensionsal array for value types to avoid unboxing (typeof(T).IsValueType ? ((T[])result)[0] : (T)result)); }
/// <summary> /// Sets a key and its value. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <param name="value">value to set</param> public virtual void Set <T>(ConfigurationKey <T> key, T value) { if (key == null) { throw new ArgumentException("key cannot be null!"); } if (value == null) { Unset(key); } else { this.configMap[key] = value; } }
/// <summary> /// Sets a key and its value. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <param name="value">value to set</param> public virtual void Set <T>(ConfigurationKey <T> key, T value) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) } if (value == null) { Unset(key); } else { this.configMap[key] = value; } }
/// <summary> /// Sets a key and its value. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <param name="value">value to set</param> public virtual void Set <T>(ConfigurationKey <T> key, T value) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) } if (value is null) { Unset(key); } else if (typeof(T).IsValueType) { this.configMap[key] = new T[] { value }; // LUCENENET: Store a 1 dimensionsal array for value types to avoid boxing } else { this.configMap[key] = value; } }
/// <summary> /// Gets the value associated with the specified key. /// </summary> /// <typeparam name="T">the value's type</typeparam> /// <param name="key">the key, cannot be <c>null</c></param> /// <param name="value">When this method returns, contains the value associated with the specified key, /// if the key is found; otherwise, the default value for the type of the <paramref name="value"/> parameter. /// This parameter is passed uninitialized.</param> /// <returns><c>true</c> if the configuration contains an element with the specified <paramref name="key"/>; otherwise, <c>false</c>.</returns> // LUCENENET specific - using this method allows us to store non-nullable value types public virtual bool TryGetValue <T>(ConfigurationKey <T> key, out T value) { if (key is null) { throw new ArgumentNullException(nameof(key), "key cannot be null!"); } if (this.configMap.TryGetValue(key, out object resultObj)) { if (typeof(T).IsValueType) { value = ((T[])resultObj)[0]; // LUCENENET: Retrieve a 1 dimensionsal array for value types to avoid unboxing } else { value = (T)resultObj; } return(true); } value = default; return(false); }