Iterator blocks and inheritance.
- by Dave Van den Eynde
Given a base class with the following interface:
public class Base
{
public virtual IEnumerable<string> GetListOfStuff()
{
yield return "First";
yield return "Second";
yield return "Third";
}
}
I want to make a derived class that overrides the method, and adds its own stuff, like so:
public class Derived : Base
{
public override IEnumerable<string> GetListOfStuff()
{
foreach (string s in base.GetListOfStuff())
{
yield return s;
}
yield return "Fourth";
yield return "Fifth";
}
}
However, I'm greeted with a warning that "access to a member through a base keyword from an iterator cannot be verified".
What's the accepted solution to this problem then?