| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Collections; |
| | 4 | |
|
| | 5 | | namespace IceRpc.Features; |
| | 6 | |
|
| | 7 | | /// <summary>Default implementation of <see cref="IRequestContextFeature" />.</summary> |
| | 8 | | /// <remarks>This class implements <see cref="IEnumerable" />, <see cref="Add" /> and the indexer operator to allow you |
| | 9 | | /// to use a collection initializer.</remarks> |
| | 10 | | public sealed class RequestContextFeature : IRequestContextFeature, IEnumerable<KeyValuePair<string, string>> |
| | 11 | | { |
| | 12 | | /// <inheritdoc/> |
| 39 | 13 | | public IDictionary<string, string> Value { get; } |
| | 14 | |
|
| | 15 | | /// <summary>Gets or sets an entry in <see cref="Value" />.</summary> |
| | 16 | | /// <param name="key">The key.</param> |
| | 17 | | /// <returns>The value.</returns>> |
| | 18 | | public string this[string key] |
| | 19 | | { |
| 0 | 20 | | get => Value[key]; |
| 0 | 21 | | set => Value[key] = value; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary>Constructs an empty writeable request context feature.</summary> |
| 16 | 25 | | public RequestContextFeature() => Value = new Dictionary<string, string>(); |
| | 26 | |
|
| | 27 | | /// <summary>Constructs a request context feature with the specified dictionary.</summary> |
| | 28 | | /// <param name="dictionary">The dictionary that the new feature will hold.</param> |
| 30 | 29 | | public RequestContextFeature(IDictionary<string, string> dictionary) => Value = dictionary; |
| | 30 | |
|
| | 31 | | /// <summary>Adds a new entry to <see cref="Value" />.</summary> |
| | 32 | | /// <param name="key">The key of the new entry.</param> |
| | 33 | | /// <param name="value">The value of the new entry.</param> |
| 0 | 34 | | public void Add(string key, string value) => Value.Add(key, value); |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| 0 | 37 | | public IEnumerator<KeyValuePair<string, string>> GetEnumerator() => Value.GetEnumerator(); |
| | 38 | |
|
| | 39 | | /// <inheritdoc /> |
| 0 | 40 | | IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Value).GetEnumerator(); |
| | 41 | | } |