I don't think I'd be stepping out of line by saying that we at OpenNETCF are renowned for taking what Microsoft have done and, well, adding more value to it. This blog post is about just one of those cases were we are already seeing ways we can make your life as a developer a much easier one. Last weekend was the first real chance I had had to play around with Visual Studio 2008 Beta 2. One of the key new features of .NET Compact Framework 3.5 that I wanted to grok was LINQ. I’ve read a lot about the technology over the last year and had briefly played around with it under Visual Studio "Orcas" Beta 1. The one thought that struck me about LINQ is the sheer power it could offer when trying to access your PIM information stored in Pocket Outlook.
The first test case I wrote at the weekend was a LINQ query to retrieve a subset of my contacts. Let's take a look at it:
var steves = from c in outlook.Contacts.Items
where c.FirstName.StartsWith("Steve")
orderby c.LastName
select new { c.FirstName, c.LastName, c.Email1Address };
The above query will search through all my contacts and return only those whose first name starts with Steve. The resulting subset will also be sorted alphabetically by the contact's last name. Also, since the Contact type contains has great number of properties, I opted to has the results only contain a subset of the properties that I was interested in. It's worth noting that the "new { ... }" notation creates a new anonymous type and that the results from the query will be a strongly typed list of this anonymous type.
With the query written, I compiled the project and was somewhat shocked to find this (click the image to enlarge it):

Meh. That's not too good. Basically, out of the box there is no LINQ support in the Pocket Outlook library. I really ought to have expected this given that the Microsoft.WindowsMobile.PocketOutlook assembly is a .NET Compact Framework v1.0 assembly. I'm the kind of guy not to be too disheartened by something like this. Afterall, it's just code, right? This got me thinking about how difficult it would be to add in the necessary query pattern so that I could run my query.
C# 3.0 has a new feature called Extension Methods. These are static methods with a specific signature and are used to add new methods to existing classes, regardless of the fact that you may not have access to the original class's source code. I dug around the System.Linq namespace in the Object Browser to see if I could find the query pattern that I would need to replicate as extension methods in order to get the LINQ query to compile. About 30 minutes or so later, I have a set of extension methods I needed and my code compiled! Since I had collected the extension methods under the Microsoft.WindowsMobile.PocketOutlook namespace, I did not have to alter any code in my original test case. Fantastic! Take a look at the screenshot below to see the output of the LINQ query:

This is not yet fully baked so I'm reluctantly to share the code, but I wanted to show you how you can achieve something awesome by leveraging a handful of the new features in .NET Compact Framework 3.5.