Fiddler's HTTPHeaders class has a member, Storage
, which is a List<HTTPHeaderItem>
.
The HTTPHeaders class exposes an enumerator in the .NET 1.1 style thusly: public System.Collections.IEnumerator GetEnumerator()
. This method simply returns Storage.GetEnumerator()
.
Questions:
Is there a performance penalty to not implementing
IEnumerable<HTTPHeaderItem>
? Or is the compilation offoreach(HTTPHeaderItem in oHTTPHeaders)
smart enough to recognize that the object it got back also implements the type-specific version of IEnumerable and avoid a bunch of casting?Is it even possible to implement
IEnumerable<HTTPHeaderItem>
without hiding (via explicit interface implementation) the older GetEnumerator() method? Hiding the old method breaks binary compatibility with legacy extensions (e.g.Method not found: 'System.Collections.IEnumerator Fiddler.HTTPHeaders.GetEnumerator()
'.)
Outcome
*As noted by Servy's answer below, there's no simple way to avoid breaking binary compatibility when adding a public GetEnumerable() that returns a type-specialized Enumerator.
However, in my specific scenario, I got a bit lucky. HTTPHeaders is a base class and virtually all callers are using one of two derived classes (HTTPRequestHeaders and HTTPResponseHeaders). I've added public generic GetEnumerator() methods to both of the each of the derived classes. These new type-specific enumerators are called by code that is compiled against the new version, while older plugins that haven't been recompiled still retrieve the non-generic Enumerator from the base class.*
IEnumerable<HTTPHeaderItem>
explicitly. The non-generic version would be the exposed one, and shouldn't break compatibility. I don't know which one aforeach
loop would use, though. - David Yaw