I have two classes, GenericList and SpecificList, where SpecificList inherits from GenericList. GenericList implements IEnumerable<GenericItem> and SpecificList implements IEnumerable<SpecificItem>. SpecificItem inherits from GenericItem. I have to implement GetEnumerator in both GenericList and SpecificList since they implement IEnumerable<T>. In GenericList, it's easy enough, I just return the enumerator for the underlying List<T>:
public IEnumerator<GenericItem> GetEnumerator()
{
return genericItemsList.GetEnumerator();
}
However, in SpecificList, it seems trickier. It seems risky to cast IEnumerator<GenericItem> to IEnumerator<SpecificItem>, and I don't know if that would even work. Instead, I did the following:
public new IEnumerator<SpecificItem> GetEnumerator()
{
IEnumerator<GenericItem> enumerator = base.GetEnumerator();
while (enumerator.MoveNext())
{
yield return (SpecificItem)enumerator.Current;
}
}
This compiles fine and a simple MSTest unit test calling SpecificList.GetEnumerator() seems to show it works. However, ReSharper highlights base in the above method with the following warning:
Access to GenericList.GetEnumerator through 'base' keyword from anonymous method, lambda expression, query expression or iterator results in unverifiable code
Is this something I should worry about? Should I do something differently?
Edit: I'm using ReSharper 5.1 Full Edition Pre-Release Build 5.1.1715.35.
Also, I should take a break from running MSTest unit tests: I just hit Ctrl+R, Ctrl+T in Chrome to reload the page...