Today I encountered the strangest .NET Framework design decision I’ve seen in recent times:
GetEnumerator method returns a
public struct HashSet<T>.Enumerator.
Let’s count how many Framework Design Guidelines this violates:
- violation: duh.
2. It is immutable.
- violation: calling
MoveNextmutates the enumerator object.
3. It will not have to be boxed frequently.
- violation: passing a
HashSet<T>as a parameter to a method that accepts
IEnumerable<T>(Linq, anyone?) will hide the class’
GetEnumeratormethod. Therefore, any calls to
GetEnumeratorcall the interface method which requires boxing the
HashSet<T>.Enumeratorto return an
4. [Any others you see? Leave a comment.]
I really want to hear the arguments in favor of the shipping design.