I have a class like this:
public partial class GmxGlobalList : DynamicBindingListBase<GmxGlobal>
Where DynamicBindingListBase implements Collection<T> which extends from IEnumerable<T> – in this case IEnumerable<GmxGlobal>.
The class GmxGlobal is defines like
public partial class GmxGlobal : IGmxGlobal
I want now to declare GmxGlobalList like
public partial class GmxGlobalList : DynamicBindingListBase<GmxGlobal>, IEnumerable<IGmxGlobal>
But this does not work, because I should declare the Method IEnumerator<IGmxGlobal> GetEnumerator() – but this is already implemented from Collection<T> – but not with IGmxGlobal but with GmxGlobal. I would ask you, why I have to implement IEnumerator<IGmxGlobal> GetEnumerator()? – What sould I do, that I can declare, that GmxGlobalList is an IEnumerable or ICollection or IList of IGmxGlobal (or something other where IGmxGlobal can be enumerated).
Since
DynamicBindingListBase<T>implementsIEnumerable<T>andGmxGlobalListinherits fromDynamicBindingListBase<GmxGlobal>and implementsIEnumerable<IGmxGlobal>.GmxGlobalListimplements bothIEnumerable<GmxGlobal>andIEnumerable<IGmxGlobal>.I’m going to assume that
DynamicBindingListBase<T>already has a concrete implementation ofIEnumerable<T>. This implementation wouldn’t work as aIEnumerable<IGmxGlobal>sinceIEnumerable<IGmxGlobal>has a wider scope thanIEnumerable<GmxGlobal>.If you were to just have the following:
Due to
IEnumerablebeing co-variant, you can already useGmxGlobalListas aIEnumerable<IGmxGlobal>. Like this:If you really need to implement
IEnumerable<IGmxGlobal>you can write the implementation details to wrap aroundDynamicBindingListBase<GmxGlobal>.