/// <summary> /// Gets the value associated with the specified key. /// </summary> /// <typeparam name="TValue">The value type.</typeparam> /// <param name="key">The key of the <see cref="BalancerAttributesKey{TValue}"/> to get.</param> /// <param name="value"> /// When this method returns, contains the value associated with the specified key, if the key is found /// and the value type matches the specified type. Otherwise, contains the default value for the type of /// the <c>value</c> parameter. /// </param> /// <returns> /// <c>true</c> if the <see cref="BalancerAttributes"/> contains an element with the specified key and value type; otherwise <c>false</c>. /// </returns> public bool TryGetValue <TValue>(BalancerAttributesKey <TValue> key, [MaybeNullWhen(false)] out TValue value) { if (_attributes.TryGetValue(key.Key, out object?o) && o is TValue v) { value = v; return(true); } value = default; return(false); }
/// <summary> /// Sets the value associated with the specified key. /// </summary> /// <typeparam name="TValue">The value type.</typeparam> /// <param name="key">The key of the value to set.</param> /// <param name="value">The value.</param> public void Set <TValue>(BalancerAttributesKey <TValue> key, TValue value) { _attributes[key.Key] = value; }