May 2008 Entries

No more null checking on your IEnumerables before you iterate over them

I get a bit sick of checking for null on my IEnumerable objects before doing a foreach over them. In my opinion I think the CLR should check if the list is null, and if it is just exit out of the foreach iteration as if there were no items in it. Well, I was goofing around with Extension Methods a bit and figured out how to get this kind of functionality (sort of). Now unfortunatly Extension Methods cant override an existing method on a type, so I cant just create a new GetEnumerator extension method ......