In C#: How to declare a generic Dictionary whose key and value types have a common constraint type?
- by Marcel
Hi all,
I want to declare a dictionary that stores typed IEnumerable's of a specific type, with that exact type as key, like so:
private IDictionary<T, IEnumerable<T>> _dataOfType where T: BaseClass; //does not compile!
The concrete classes I want to store, all derive from BaseClass, therefore the idea to use it as constraint. The compiler complains that it expects a semicolon after the member name.
If it would work, I would expect this would make the later retrieval from the dictionary simple like:
IEnumerable<ConcreteData> concreteData;
_sitesOfType.TryGetValue(typeof(ConcreteType), out concreteData);
How to define such a dictionary?