| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Collections; |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | |
| | | 6 | | namespace IceRpc.Features.Internal; |
| | | 7 | | |
| | | 8 | | /// <summary>A feature collection decorator that does not allow updates to the underlying feature collection.</summary> |
| | | 9 | | internal class ReadOnlyFeatureCollectionDecorator : IFeatureCollection |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc/> |
| | 175 | 12 | | public bool IsReadOnly => true; |
| | | 13 | | |
| | | 14 | | private readonly IFeatureCollection _decoratee; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc/> |
| | | 17 | | public object? this[Type key] |
| | | 18 | | { |
| | 0 | 19 | | get => _decoratee[key]; |
| | 0 | 20 | | set => throw new InvalidOperationException("Cannot update a read-only feature collection."); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | 0 | 24 | | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | 0 | 27 | | public IEnumerator<KeyValuePair<Type, object>> GetEnumerator() => _decoratee.GetEnumerator(); |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | 507 | 30 | | public TFeature? Get<TFeature>() => _decoratee.Get<TFeature>(); |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | 0 | 33 | | public void Set<TFeature>(TFeature? feature) => _decoratee.Set(feature); |
| | | 34 | | |
| | | 35 | | /// <summary>Constructs a read-only feature collection over another feature collection.</summary> |
| | | 36 | | /// <param name="decoratee">The decoratee.</param> |
| | 14 | 37 | | internal ReadOnlyFeatureCollectionDecorator(IFeatureCollection decoratee) |
| | 14 | 38 | | { |
| | 14 | 39 | | Debug.Assert(!decoratee.IsReadOnly); |
| | 14 | 40 | | _decoratee = decoratee; |
| | 14 | 41 | | } |
| | | 42 | | } |