To begin, this question is very similar but not the same as How to call an explicitly implemented interface-method on the base class .
My problem is that I cannot even add any helper method to the base class in question to work around the issue addressed in that question.
The code:
class AsyncObservableCollection<T> : ObservableCollection<T>
{
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return new ThreadSafeEnumerator<T>(this.GetEnumerator(), this.mutex);
}
}
Where ObservableCollection<T>
comes from Collection<T>
which implements IEnumerable<T>
.
The compile error:
AsyncObservableCollection<T>.IEnumerable<...>.GetEnumerator()':
containing type does not implement interface 'System.Collections.Generic.IEnumerable<T>
The question:
So my aim is to have any foreach loops using an instance of my AsyncObservableCollection<T>
to get my custom enumerator while allowing this.GetEnumerator()
in my custom method still get the 'standard' enumerator. I'm not sure what is the best way to do this.