Monday, April 30, 2007

Google Linq

The ultimate way to understand LINQ, of course, is to write your own IQueryable magic. I have choosed Google Image as my first pet project for this: The reason for selecting Image over Web search is that Image results are more structured. For example, we can filter on size, type and color. Implementing all these would provide a more complete view of the inner working of LINQ/IQueryable.

Base on the principles of TDD, I shall first define the test cases for the project, for example:

var test = from img in


           where img.Description.Contains("linq")

               && img.Size == ImageSize.Small

           select img;

I intend to define ImageSearch as a singleton because, well, there is only one Google… Obviously this can be further extended to Web, Group and Froogle in the future.

As the very first step, I have put togather a crude implementation of IQueryable that simply dumps the Expression tree in CreateQuery function. The output for the query expression above looks like:

Some references that are very useful along the way: