EditLINQ to Objects
LINQ to Object operators are simply extension methods on any type that implements
IEnumerable<T>.
Writing a new LINQ to Object query operator sounds more complicated than it actually is. The standard query operators supplied by Microsoft rarely span more than a few lines of code each. The operators make heavy use of the introduced language features in C# 2.0 (Released as part of Visual Studio 2005), especially the yield return keyword which makes writing iterators easier. The first port of call when wanting to understand how to write an operator is to look at the source code for the
Standard Query Operators. Since the release of version 3.5 of the framework, the implementation of System.Linq.Enumerable found in the System.Core assembly is where most of the
Standard Query Operators can be found.
Reflector can be used to view a decompilation of the released assembly.
The query operators fall into a few different categories, and the implementation pattern for each of these differ.
1. Operators that return a Single Element. E.g. First, Last.
2. Operators that return a Sequence. E.g. Where, Select.
3. Operators that return an Aggregate result. E.g. Count, Min, Max, Average.
4. Operators that return groupings. E.g. GroupBy, GroupJoin