It seems to me like I should be able to do this? But I can't.
public Dictionary<Type, List<ParserRuleContext>> Contexts { get; private set; }
public IEnumerable<T> GetAllContextsOfType<T>() where T:ParserRuleContext
{
return (List<T>)Contexts[typeof(T)];
}
This produces the error:
Cannot convert type 'System.Collections.Generic.List<ParserRuleContext>'
to 'System.Collections.Generic.List<T>'
Given that List is constrained to be List<ParserRuleContext> by the where clause, I don't understand this?
I believe that should be the fact that the instance of the list being with a different tipage the list in the dictionary, if you make a cast with linq is to solve
return Contexts[typeof(T)].Cast<T>();
or
return Contexts[typeof(T)].ToList<T>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With