I have a ´switch´ which receives a object
. If I use a it list
works fine, but if I use a Dictionary
it doesn't work.
object data = DataStructureFactory.Make();
switch (data)
{
case IEnumerable<IEntity> listStackOrQueue:
// works
case IEnumerable<KeyValuePair<Guid,IEntity>> keyValuePair:
// don't works
case IDictionary<Guid,IEntity> dictionary:
// don't works
default:
throw new InvalidCastException(
"El tipo {0}, no pudo ser reconocido.",
data.GetType().Name);
}
When I run it I get the following error:
The type Dictionary`2, could not be recognized.
I noticed that the interface has the outIEnumerable
modifier , so I did some research on the matter and found about Variance in Generic Interfaces . I don't know if it has something to do with it, but I haven't solved the problem yet. IEnumerable<out T>