I\'m trying to create a wrapper for a Dictionary
.
Dictionary
implements IEnumerable
The problem is that there is no such thing as return type covariance in .NET - IEnumerator M()
and IEnumerator<Foo> M()
are completely different methods.
The workaround is that you have to implement the non-generic version explicitly:
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
// this calls the IEnumerator<Foo> GetEnumerator method
// as explicit method implementations aren't used for method resolution in C#
// polymorphism (IEnumerator<T> implements IEnumerator)
// ensures this is type-safe
return GetEnumerator();
}