Compartilhar via


Framework Design Guidelines: LINQ Support

Continuing in our weekly blog post series that highlights a few of the new image[5]_thumb[2]_thumb[2]_thumbadditions to the Framework Design Guidelines 2nd edition.. This content is found in the LINQ section of Chapter 9: Common Design Patterns.

Supporting LINQ through IEnumerable<T>

DO implement IEnumerable<T> to enable basic LINQ support.

Such basic support should be sufficient for most in-memory data sets. The basic LINQ support will use the extension methods on IEnumerable<T> provided in the .NET Framework. For example, simply defineing as follows:

public class RangeOfInt32s : IEnumerable<int> {
   public IEnumerator<int> GetEnumerator() {…}
   IEnumerator IEnumerable.GetEnumerator() {…}
}

Doing so Allows for the following code, despite the fact that RangeOfInt32s did not implement a Where method:.

var a = new RangeOfInt32s();
var b = a.Where(x => x>10);

RICO MARIANI

Keeping in mind that you’ll get your same enumeration semantics, and putting a Linq façade on them does not make them execute any faster or use less memory.

Comments

  • Anonymous
    March 09, 2009
    PingBack from http://www.anith.com/?p=17019

  • Anonymous
    March 09, 2009
    Continuing in our weekly blog post series that highlights a few of the new additions to the Framework

  • Anonymous
    March 10, 2009
    Thank you for submitting this cool story - Trackback from DotNetShoutout

  • Anonymous
    March 10, 2009
    Windows Azure/Cloud Computing Cloud Computing Links March 10, 2009 Windows Azure and Cloud Computing Posts for 3/9/2009+ Agile/Mocks/Software Design/Software Development Tools Moq 3.0 RTM!!! Scott Ambler shares the the Manifesto for Software Craftsmanship