| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Features.Internal; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Features; |
| | | 6 | | |
| | | 7 | | /// <summary>Provides extension methods for <see cref="IFeatureCollection" />.</summary> |
| | | 8 | | public static class FeatureCollectionExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary>Creates a read-only collection decorator over this feature collection.</summary> |
| | | 11 | | /// <param name="features">This feature collection.</param> |
| | | 12 | | /// <returns>A new read-only decorator over this feature collection, or the feature collection itself if it's |
| | | 13 | | /// already read-only.</returns> |
| | | 14 | | public static IFeatureCollection AsReadOnly(this IFeatureCollection features) => |
| | 14 | 15 | | features.IsReadOnly ? features : new ReadOnlyFeatureCollectionDecorator(features); |
| | | 16 | | |
| | | 17 | | /// <summary>Updates this feature collection (if read-write) or creates a new feature collection (if read-only) |
| | | 18 | | /// and sets its T to the provided value.</summary> |
| | | 19 | | /// <typeparam name="T">The type of the value to set in the feature collection.</typeparam> |
| | | 20 | | /// <param name="features">This feature collection.</param> |
| | | 21 | | /// <param name="value">The new value.</param> |
| | | 22 | | /// <returns>The updated feature collection.</returns> |
| | | 23 | | public static IFeatureCollection With<T>(this IFeatureCollection features, T value) |
| | 296 | 24 | | { |
| | 296 | 25 | | if (features.IsReadOnly) |
| | 175 | 26 | | { |
| | 175 | 27 | | features = new FeatureCollection(features); |
| | 175 | 28 | | } |
| | 296 | 29 | | features.Set(value); |
| | 296 | 30 | | return features; |
| | 296 | 31 | | } |
| | | 32 | | } |