I need to create a class that:
- manipulates a
Dictionary<int, List<string>>
internally - exposes it as a property of type
IReadOnlyDictionary<int, IEnumerable<string>>
The latter requirement cannot be changed unfortunately. Due to the (understandable) limitations of covariance in C#, the following does not work:
private Dictionary<int, List<string>> things;
public IReadOnlyDictionary<int, IEnumerable<string>> Things => things; // compile time error
The class needs to mutate the dictionary and the lists, so I cannot change the private field to be of the interface type.
What is the most succinct way, preferably using Linq, to convert a Dictionary<int, List<string>>
to an IReadOnlyDictionary<int, IEnumerable<string>>
?