Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f420369

Browse files
committed
Fix WebHeaderCollection.GetEnumerator().
Change WebHeaderCollection.GetEnumerator() from an explicit implementation to a public override to avoid delegating to the base collection. This change also adds a test for this behavior.
1 parent 096b156 commit f420369

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/System.Net.WebHeaderCollection/src/System/Net/WebHeaderCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public override string[] AllKeys
593593
}
594594
}
595595

596-
IEnumerator IEnumerable.GetEnumerator()
596+
public override IEnumerator GetEnumerator()
597597
{
598598
return InnerCollection.Keys.GetEnumerator();
599599
}

src/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,21 @@ public void ToString_Success()
250250
"Accept: text/plain\r\nContent-Length: 123\r\n\r\n",
251251
w.ToString());
252252
}
253+
254+
[Fact]
255+
public void IterateCollection_Success()
256+
{
257+
WebHeaderCollection w = new WebHeaderCollection();
258+
w["Accept"] = "text/plain";
259+
w["Content-Length"] = "123";
260+
261+
string result = "";
262+
foreach (var item in w)
263+
{
264+
result += item;
265+
}
266+
267+
Assert.Equal("AcceptContent-Length", result);
268+
}
253269
}
254270
}

0 commit comments

Comments
 (0)