I\'m trying to create a wrapper for a Dictionary.
Dictionary implements IEnumerable
When implementing IEnumerable, you must also explicitly implement IEnumerable.GetEnumerator(). The method for the generic interface is not valid in and of itself as an implementation for the non-generic method contract. You can have one call the other, or since you have a child object whose enumerator you are using, just copy/paste;
using System.Collections;
using System.Collections.Generic;
public class FooCollection : IEnumerable
{
private Dictionary fooDictionary = new Dictionary();
public IEnumerator GetEnumerator()
{
return fooDictionary.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
//forces use of the non-generic implementation on the Values collection
return ((IEnumerable)fooDictionary.Values).GetEnumerator();
}
// Other wrapper methods omitted
}