[API Proposal]: Add a generic ReadOnlyOrderedDictionary class
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Background and motivation
We now have a generic `OrderedDictionary` and a `ReadOnlyDictionary` but no combination of the two. We have need of such a data structure where the key order is important and we also want it to be immutable.
### API Proposal
```csharp
namespace System.Collections.Generic;
public class ReadOnlyOrderedDictionary :
IDictionary, IReadOnlyDictionary, IDictionary,
IList>, IReadOnlyList>, IList
where TKey : not null
{
// Same methods/properties as ReadOnlyDictionary, but enumerations are ordered
}
```
### API Usage
```csharp
var dict = new ReadOnlyOrderedDictionary(
[
new KeyValuePair("foo","bar"),
new KeyValuePair("foo1","bar2"),
]);
foreach ((var key, var value) in dict)
{
// ...
}
```
### Alternative Designs
_No response_
### Risks
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.