Converting Dictionary<TKey, List<TValue>> to ReadOnlyDictionary<TKey, ReadOnlyCollection<TValue>>
One possibility (probably suboptimal for large collections) would be to construct a new Dictionary
object of the desired type (using the Enumerable.ToDictionary overload) and use the List.AsReadOnly() extension like this:
var readOnlyDictionary =
new ReadOnlyDictionary<Role, ReadOnlyCollection<Action>>
(dictionary.ToDictionary(k => k.Key, v => v.Value.AsReadOnly()));
Converting a Dictionary to a ReadOnlyDictionary is as simple as passing the regular dictionary as a parameter to the constructor of ReadOnlyDictionary:
var myDict = new Dictionary<K, V>();
var myReadOnlyDict = new ReadOnlyDictionary<K, V>(myDictionary);