-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add an ISet<T>.AsReadOnly() extension method #29387
Copy link
Copy link
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.CollectionsenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.CollectionsenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Type
Fields
Give feedbackNo fields configured for issues without a type.
The
List<>class have aAsReadOnlymethod to turn the collection into aReadOnlyCollection, butHashSet<>does not have any such method.Rationale and usage
Allows Entity Framework Core to expose a collection navigation property as a
IReadOnlyCollectionwhen backing it with a private backing field declared as aHashSet.Proposed API
namespace System.Collections.Generic; public class CollectionExtensions { public ReadOnlyCollection<T> AsReadOnly(this IList<T> list); public ReadOnlyDictionary<T> AsReadOnly(this IDictionary<T> dictionary); + public ReadOnlySet<T> AsReadOnly(this ISet<T> set); }