Making ConfigurationElementCollection Strongly Typed.

I was getting annoyed with ConfigurationElementCollection returning IEnumerable and not IEnumerable, after some Googling I came across this post on StackOverflow https://stackoverflow.com/questions/7991252/read-web-config-section-to-list.

Basically you implement IEnumerable and in GetEnumerator do this

1
2
3
4
public new IEnumerator GetEnumerator()
{
return this.OfType().GetEnumerator();
}

No more casting when you want to use Linq on the ConfigurationElementCollection