What I mean is, iterate through a collection of SPListItems and parse each of them to an entity in your domain model (in the example I´m just using a anonymous type to do that). There´s a lot of int.Parse and bool.Parse and so going on, really tiresome code. What I also should be doing is to check for null and if the field actually exists on the SPListItem.
There´s gotto be something better we can do. So, here goes:

My inspiration comes from the DataRowExtensions class and the Field<T> method. With that extension you can write code that looks like this:int i = r.Field<int>(“MyColumn”);

So, my mission will be to write something like this for SPListItems and make an extension method that looks just like that. So the final code will look like this (same as first example apart from the new extension method calls in the select statement):

This class, that does all the magic, has a static constructor that gets called every time someone asks for the public Converter delegate Convert.
The constructor will then call on the private Create method that determines what implementation of the delegate to pass back.
There´s one for each case, so three implementations that look like this:

Note: I´m using the name of the field to get somewhat better error messages, ie a guid won´t tell us much.Note: I have used the same technique for extracting typed values from XElements in an xml file parser also.

UPDATE 2010-02-20: The code for the data converter and the extension method can now be found at codeplex.