New "Orcas" Language Feature: Extension Methods

Last week I started the first in a series of blog posts I'll be making that cover some of the new VB and C# language features that are coming as part of the Visual Studio and .NET Framework "Orcas" release later this year. 

My last blog post covered the new Automatic Properties, Object Initializer and Collection Initializer features.  If you haven't read my previous post yet, please read it here.  Today's blog post covers a much more significant new feature that is available with both VB and C#: Extension Methods.

What are Extension Methods?

Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.  Extension Methods help blend the flexibility of "duck typing" support popular within dynamic languages today with the performance and compile-time validation of strongly-typed languages.

Extension Methods enable a variety of useful scenarios, and help make possible the really powerful LINQ query framework that is being introduced with .NET as part of the "Orcas" release.

Simple Extension Method Example:

Ever wanted to check to see whether a string variable is a valid email address?  Today you'd probably implement this by calling a separate class (probably with a static method) to check to see whether the string is valid.  For example, something like:

string email Request.QueryString["email"];

if 
( EmailValidator.IsValid(email) ) {
   

}

Using the new "extension method" language feature in C# and VB, I can instead add a useful "IsValidEmailAddress()" method onto the string class itself, which returns whether the string instance is a valid string or not.  I can then re-write my code to be cleaner and more descriptive like so:

string email Request.QueryString["email"];

if 
( email.IsValidEmailAddress() ) {
   

}

How did we add this new IsValidEmailAddress() method to the existing string type?  We did it by defining a static class with a static method containing our "IsValidEmailAddress" extension method like below:

public static class ScottGuExtensions
{
    
public static bool IsValidEmailAddress(this string s)
    {
        Regex regex 
= new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
        return 
regex.IsMatch(s);
    
}
}

Note how the static method above has a "this" keyword before the first parameter argument of type string.  This tells the compiler that this particular Extension Method should be added to objects of type "string".  Within the IsValidEmailAddress() method implementation I can then access all of the public properties/methods/events of the actual string instance that the method is being called on, and return true/false depending on whether it is a valid email or not.

To add this specific Extension Method implementation to string instances within my code, I simply use a standard "using" statement to import the namespace containing the extension method implementation:

using ScottGuExtensions;

The compiler will then correctly resolve the IsValidEmailAddress() method on any string.  C# and VB in the public "Orcas" March CTP now provide full intellisense support for extension methods within the Visual Studio code-editor.  So when I hit the "." keyword on a string variable, my extension methods will now show up in the intellisense drop-downlist:

The VB and C# compilers also naturally give you compile-time checking of all Extension Method usage - meaning you'll get a compile-time error if you mis-type or mis-use one.

[Credit: Thanks to David Hayden for first coming up with the IsValidEmailAddress scenario I used above in a prior blog post of his from last year.]

Extension Methods Scenarios Continued...

Leveraging the new extension method feature to add methods to individual types opens up a number of useful extensibility scenarios for developers.  What makes Extension Methods really powerful, though, is their ability to be applied not just to individual types - but also to any parent base class or interface within the .NET Framework.  This enables developers to build a variety of rich, composable, framework extensions that can be used across the .NET Framework.

For example, consider a scenario where I want an easy, descriptive, way to check whether an object is already included within a collection or array of objects.  I could define a simple .In(collection) extension method that I want to add to all objects within .NET to enable this.  I could implement this "In()" extension method within C# like so:

Note above how I've declared the first parameter to the extension method to be "this object o".  This indicates that this extension method should applied to all types that derive from the base System.Object base type - which means I can now use it on every object in .NET. 

The "In" method implementation above allows me to check to see whether a specific object is included within an IEnumerable sequence passed as an argument to the method.  Because all .NET collections and arrays implement the IEnumerable interface, I now have a useful and descriptive method for checking whether any .NET object belongs to any .NET collection or array.

I could use then use this "In()" extension method to see whether a particular string is within an array of strings:

I could use it to check to see whether a particular ASP.NET control is within a container control collection:

I could even use it with scalar datatypes like integers:

Note above how you can even use extension methods on base datatype values (like the integer value 42).  Because the CLR supports automatic boxing/unboxing of value-classes, extensions methods can be applied on numeric and other scalar datatypes directly. 

As you can probably begin to see from the samples above, extension methods enable some really rich and descriptive extensibility scenarios.  When applied against common base classes and interfaces across .NET, they enable some really nice domain specific framework and composition scenarios. 

Built-in System.Linq Extension Methods

One of the built-in extension method libraries that we are shipping within .NET in the "Orcas" timeframe are a set of very powerful query extension method implementations that enable developers to easily query data.  These extension method implementations live under the new "System.Linq" namespace, and define standard query operator extension methods that can be used by any .NET developer to easily query XML, Relational Databases, .NET objects that implement IEnumerable, and/or any other type of data structure. 

A few of the advantages of using the extension method extensibility model for this query support include:

1) It enables a common query programming model and syntax that can be used across all types of data (databases, XML files, in-memory objects, web-services, etc).

2) It is composable and allows developers to easily add new methods/operators into the query syntax. For example: we could use our custom "In()" method together with the standard "Where()" method defined by LINQ as part of a single query.  Our custom In() method will look just as natural as the "standard" methods supplied under the System.Linq namespace. 

3) It is extensible and allows any type of data provider to be used with it.  For example: an existing ORM engine like NHibernate or LLBLGen could implement the LINQ standard query operators to enable LINQ queries against their existing ORM implementation and mapping engines.  This will enable developers to learn a common way to query data, and then apply the same skills against a wide variety of rich data store implementations.

I'll be walking through LINQ much more over the next few weeks, but wanted to leave you with a few samples that show how to use a few of the built-in LINQ query extension methods with different types of data:

Scenario 1: Using LINQ Extension Methods Against In-Memory .NET Objects

Assume we have defined a class to represent a "Person" like so:

I could then use the new object Initializer and collection Initializer features to create and populate a collection of "people" like so:

I could then use the standard "Where()" extension method provided by System.Linq to retrieve a sequence of those "Person" objects within this collection whose FirstName starts with the letter "S" like so:

The new p => syntax above is an example of a "Lambda expression", which is a more concise evolution of C# 2.0's anonymous method support, and enables us to easily express a query filter with an argument (in this case we are indicating that we only want to return a sequence of those Person objects where the firstname property starts with the letter "S").  The above query will then return 2 objects as part of the sequence (for Scott and Susanne).

 I could also write code that takes advantage of the new "Average" and "Max" extension methods provided by System.Linq to determine the average age of the people in my collection, as well as the age of the oldest person like so:

Scenario 2: Using LINQ Extension Methods Against an XML File

It is probably rare that you manually create a collection of hard-coded data in-memory.  More likely you'll retrieve the data either from an XML file, a database, or a web-service.

Let's assume we have an XML file on disk that contains the data below:

I could obviously use the existing System.Xml APIs today to either load this XML file into a DOM and access it, or use a low-level XmlReader API to manually parse it myself.  Alternatively, with "Orcas" I can now use the System.Xml.Linq implementation that supports the standard LINQ extension methods (aka "XLINQ") to more elegantly parse and process the XML. 

The below code-sample shows how to use LINQ to retrieve all of the <person> XML Elements that have a <person> sub-node whose inner value starts with the letter "S":

Note that it uses the exact same Where() extension method as with the in-memory object sample.  Right now it is returning a sequence of "XElement" elements, which is an un-typed XML node element.  I could alternatively re-write the query to "shape" the data that is returned instead by using LINQ's Select() extension method and provide a Lambda expression that uses the new object initializer syntax to populate the same "Person" class that we used with our first in-memory collection example:

The above code does all the work necessary to open, parse and filter the XML in the "test.xml" file, and return back a strongly-typed sequence of Person objects.  No mapping or persistence file is necessary to map the values - instead I am expressing the shaping from XML->objects directly within the LINQ query above.

I could also use the same Average() and Max() LINQ extension methods as before to calculate the average age of <person> elements within the XML file, as well as the maximum age like so:

I do not have to manually parse the XML file.  Not only will XLINQ handle that for me, but it will parse the file using a low-level XMLReader and not have to create a DOM in order to evaluate the LINQ expression.  This means that it is lightening fast and doesn't allocate much memory.

Scenario 3: Using LINQ Extension Methods Against a Database

Let's assume we have a SQL database that contains a table called "People" that has the following database schema:

I could use the new LINQ to SQL WYSIWYG ORM designer within Visual Studio to quickly create a "Person" class that maps to the database:

I can then use the same LINQ Where() extension method I used previously with objects and XML to retrieve a sequence of strongly-typed "Person" objects from the database whose first name starts with the letter "S":

Note how the query syntax is the same as with objects and XML. 

I could then use the same LINQ Average() and Max() extension methods as before to retrieve the average and maximum age values from the database like so:

You don't need to write any SQL code yourself to have the above code snippets work.  The LINQ to SQL object relational mapper provided with "Orcas" will handle retrieving, tracking and updating objects that map to your database schema and/or SPROCs.  You can simply use any LINQ extension method to filter and shape the results, and LINQ to SQL will execute the SQL code necessary to retrieve the data (note: the Average and Max extension methods above obviously don't return all the rows from the table - they instead use TSQL aggregate functions to compute the values in the database and just return a scalar result).

Please watch this video I did in January to see how LINQ to SQL dramatically improves data productivity in "Orcas".  In the video you can also see the new LINQ to SQL WYSIWYG ORM designer in action, as well as see full intellisense provided in the code-editor when writing LINQ code against the data model.

Summary

Hopefully the above post gives you a basic understanding of how extension methods work, and some of the cool extensibility approaches you will be able to take with them.  As with any extensibility mechanism, I'd really caution about not going overboard creating new extension methods to begin with.  Just because you have a shiny new hammer doesn't mean that everything in the world has suddenly become a nail!  

To get started trying out extension methods, I'd recommend first exploring the standard query operators provided within the System.Linq namespace in "Orcas".  These enable rich query support against any array, collection, XML stream, or relational database, and can dramatically improve your productivity when working with data.  I think you'll find they'll significantly reduce the amount of code you write within your applications, and allow you to write really clean and descriptive syntax.  They'll also enable you to get automatic intellisense and compile-time checking of query logic within your code.

In the next few weeks I'll continue this series on new language features in "Orcas" and explore Anonymous Types and Type Inference, as well as talk more about Lambdas and other cool features.  I'll also obviously be talking a lot more about LINQ.

[April 21st Update: I recently posted the next topic in this Orcas language series - covering Query Syntax -- here.]

Hope this helps,

Scott

Published Tuesday, March 13, 2007 2:27 AM by ScottGu
Filed under: , , , ,

Comments

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 6:02 AM by Jens Hofmann

I think Extension Methods in Orcas are great. I've played a bit the new features and I'm very happy with it. There are so much possibilities now.

I'm abled to fill the gap of the missing:

string.TrimIsNullOrEmpty - Method

I've never understood why there was no overload for string.IsNullOrEmpty to also do a trim().

Thanks!

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 7:12 AM by Rachit

The "In" is definitely very useful...I've been looking for something like this a long time back...cool!

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 7:16 AM by dominick

Hi Scott,

well - this is cool - somehow...

Extension methods may be funky and geeky (and even very useful) - but they will make understanding code (let alone code reviews) *much* harder in the future...

What is your opinion on that? How do you handle this fact (especially the code review part) internally...?

thanks

dominick

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 8:23 AM by Chris Moseley

Hi Scott,

How does the performance of these in-built linq tools measure up? e.g how does loading and parsing an xml file using XLinq compare with using System.Xml?

Extension Methods look like a nice idea but I can see them being a bit confusing to new programmers.

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 8:25 AM by Daniel Moth

If anybody is interested in the VB syntax, feel free to visit my blog :-)

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 8:52 AM by Sahil Malik

Scott,

Are these Orcas features, or new features in C# 3.0? This is causing some confusion IMO.

For instance, will I be able to use extension methods in C# 2.0 using Orcas? I'm guessing the answer is "no". But will I be able to target .NET 2.0 using Orcas? The last I heard, the answer was "yes".

So, if I cannot use extension methods in C# 2.0 using Orcas, then it isn't really an Orcas feature is it?

SM

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 10:16 AM by nstlgc

You write "I simply use a standard 'using' statement to import the namespace containing the extension method implementation", but it seems as if you're importing the class instead of the namespace... Typo or coincidence?

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 10:19 AM by Angry c# guy

Why you killing the language?

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 10:38 AM by Brian Di Croce

Hey Scott!

I learned a couple of weeks ago that you changed your position within Microsoft and have now "inherited" more responsibilities.  

Congratulations!  

My comment is just to say 'Thanks!' for taking time in writing about new features coming up in the .NET framework and for being very pragmatic...even past midnight! (Did I read correctly? You wrote this post at 2:27 AM?)

Take care! ;)

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 10:55 AM by cgm

excellent post scott!  when do you think you all will release a beta 1 of orcas - soon???

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:26 AM by Erick

The new extension methods sound like they could be quite useful in a number of situations.  

Can an extension method be applied to a sealed class?

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:45 AM by ScottGu

Hi Dominick,

When used correctly, I think you'll find that Extension Methods can significantly improve code comprehension within code reviews, and lead to fewer lines of code and fewer bugs.

The reason I think this is because they allow you to more clearly express your intent.  For example, instead of a filter like below with imperitive code:

List<Person> origionalList = ...;

List<Person> results = new List<Person>;

foreach(Person p in origionalList) {

  if (p.Age > 50) {

     results.Add(p);

  }

}

You could instead just write:

results = origionaList.Where(p=>p.Age > 50).ToList();

If your conditional and filtering logic was complicated, I believe you'll find that the implementation using LINQ will be much easier to read and understand the intent.  Usually this leads to better code and fewer bugs (whereas large unfactored imperitive code blocks are usually rife with bugs).

Where you want to be careful is to make sure you don't use extension methods just for silly pet tricks.  That is why I suggested in the article above that you start just by using the built-in LINQ extension methods, and not go overboard creating your own just yet until you really understand them well and how best to use/create new ones.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:46 AM by Jason Kealey

Personally, I don't feel the need to use extension methods and agree with dominick about code reviews.

LINQ does look powerful, however!

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:46 AM by ScottGu

Hi Erick,

Yep - Extension Methods can be used on Sealed Classes, which is one place they can be very useful.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:47 AM by ScottGu

Hi Brian,

Thanks. :-)  

I've actually had my new role now for about 18 months.  It still keeps me busy though. ;-)

And sadly the post was at 2:27am.  It took a few hours longer than I was planning to write.

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:49 AM by ScottGu

Hi nstlgc,

Sorry for the confusion - it is the namespace that you want to import with the using statement.  In my code example above, both the class and namespace have the same name which was confusing.

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:51 AM by ScottGu

Hi Sahil,

Extension Methods are actually implemented entirely by the compiler - no new IL instructions within the CLR are required to support them.

This means that you can use the VS "Orcas" C# compiler and write code that uses Extension Methods, and use the multi-targetting features to run it on a vanilla .NET 2.0 box.

What is included within the "Orcas" .NET Framework are the LINQ libraries and namespace.  If you want to use the LINQ extension methods that are built-in, you'll need to have "Orcas" installed.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:52 AM by ScottGu

Hi Moth,

Nice post on using VB with extension methods: http://danielmoth.com/Blog/2007/02/extension-methods-c-30-and-vb9.html

Thanks!

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:54 AM by ScottGu

Hi Chris,

I think you'll find that XLINQ is faster at parsing XML except if you are a real expert at using the low-level XML XMLReader API (which is a fairly low-level API).

If you are getting your XML using the DOM or XQuery today, then XLINQ should be faster (since it is using the more efficient low-level System.XML APIs).

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 11:55 AM by ScottGu

Hi Chris,

Yes - the DLINQ data model classes do support serialization across web-services.

You can also attach a standalone object to the datacontext object - which allows for update scenarios across web-services as well.

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 12:15 PM by Erick

Hi Scott, when using extension methods what kind of access do we have to the base class?  Would we have access to protected methods and data as we would if we inherited from the base class or are we restricted to public access only?  

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 12:35 PM by West

Thanks Scott. Another great article :-)

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 12:43 PM by dominick

Hi Scott,

OK - well, if people would read your summary basically saying "don't overdo it" - things are fine...and in the context of Linq this is totally powerful...

I just have the fear that people will overdo it..time will tell..

It will be interesting to see what the "framework design guidelines" have to say in 12 months...

cheers

dominick

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 12:48 PM by Khuzema

Hi,

I tried to mentioned this point before on your blog and I am mentioning it again. As you are doing great job with VS and Asp.net and adding new feature(s).

I have this humble suggestion about using C# for writing both server-side and client-side code. Something like a attribute on the function,same as [WebMethod] attribute. For example -

[Server] //which should run on server

Function Foo(){}

[Client] //should run as client-side code

Function Bar(){}

So as we dont need to learn JavaScript for it. And Framework can restrict certain functionality in a code depending on [Server] or [Client] attribute.

thanks & regards

Khuzema, Kuwait

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 12:51 PM by Jeff

Gosh... I'm really hesitant to form an opinion. I agree that it's very powerful, and very cool, but I too worry about code readability and how it would affect code reviews. I guess I'll have to wait and see.

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 1:14 PM by Sahil Malik

Holy moly, thanks for the clarification Scott. This is HUGE - why don't you point that out more clearly in your blogposts, that these things are not specific to C# 3.0 only.

BTW - another thing I feel you should add is,

DONOT MISUSE Extension methods!!

:)

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 2:18 PM by Brad

While i can see times where this will be useful, hand and in good style, i am fully sure this will spawn more than a few dailywtf's (see http://www.thedailywtf.com if you havent).  

This feature will be very much like partial classes.  I once saw a team make an "Order" class that was spread into about 10 different "partial" classes that provided methods that were very clearly not proper to put on the Order class (everything from payment processors to fulfillment, it was horrible).  With great power...

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 3:42 PM by hp

Hey Scott,

Thanks for taking time out and posting things in such great detail.. only question I have is about the "Lambda expression", seems it always is P=> as we are working with the person class in all the queries. Is it possible for it to be anything other than that?? if no then why is it required?

Also I am not sure if its true for others but I am finding it difficult to read the code with Linq extension methods specially, people.decendents("person").Where( p=>p.FirstName.StartsWith("S").Select...

a word by word english translation will help!!

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 4:31 PM by Andy Alm

Thanks for the post Scott.  I'm a little confused, however, by your comparison of Extension Methods to Duck Typing.  While Extension methods are really cool, they seem to me more comparable to a feature like Ruby Mixins rather than Duck Typing.

The "var" keyword in c# 3.0 seems to be a way to achieve Duck Typing with local variables, but I have yet to see a way to achieve it outside of local variable scope.  Am I missing something?

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:09 PM by Amrinder Sandhu

Hi Scott,

Thanks for great article.

Is it possible to add a property to existing class? Or are we only allowed to add methods? For example, in the Valid Email address example, it would be nice to just write bool isValid = email.IsValidEmailAddress;

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:14 PM by Mads Kristensen

I'm really looking forward to this. The partial classes of .NET 2.0 was a step of the way, but this just takes it though the roof. Excellent.

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:26 PM by kevindente

Scott,

Cool stuff. But since Microsoft's own guidance is don't extend types that you don't own, perhaps samples extending string and IEnumerable aren't the best ones to put out there. Extension methods have to potential to cause serious maintenance problems if misused.

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:40 PM by ScottGu

Hi Kevin,

I'm not entirely sure what you mean about not extending types you don't own - since we do this quite a bit today (for example: sub-classing controls, pages, providers, etc).

In general, you do need to be careful/thoughtful about how you extend existing types.  With extension methods, you can just use the public type contract for the type/interface you are working against - this should keep you safe going forward from an extensibility perspective.

Note also that extension methods don't change the origional object type itself, so other compiled control libraries that work with the same type won't be affected.  This also makes it far less brittle than changing the object dynamically at runtime.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:41 PM by ScottGu

Hi Amrinder,

Right now we don't support extension properties.  It is something I know the language teams are considering for the future - but for right now you can only add methods.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:43 PM by ScottGu

Hi hp,

I'll do an upcoming post on Lambda expressions that help explain how to use them more.  

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:48 PM by JFo

This is very cool.  Will the framework itself make use of extension methods?  

e.g. It seems like it would be strange to get new string methods if you included System.Drawing...  How would the documentation work?

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 5:58 PM by ScottGu

Hi JFo,

In the "Orcas" release the only framework extensions that take advantage of extension methods is with LINQ.

I doubt we'd ever add extension methods to existing namespaces.  Instead we'd probably add extensions to sub-namespaces (like System.Xml.Linq) so as to keep things clear.

As I mentioned in my blog post above, you want to be careful about where and how exactly you use it.  It is a powerful tool, but you don't want to be careful not to use it.  Likewise we'll be careful with the .NET Framework about the places we leverage it to make sure it totally makes sense and integrates cleanly.

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 7:01 PM by Roger

Hi Scott,

In .net 2.0, I typically create a data layer which returns generic lists of objects. For example:

public static List<Widget> GetAllWidgets(){...}

I call a stored procedure in that method and map the resulting dataset into the strong-typed object list.

The ORM designer interests me because if it can generate the same methods and classes it would save a lot of time.

However, as the owner of the data layer I don't want a developer to use LINQ to do things that a stored procedure would be best at.

For example:

public static List<Widget> GetWidgetsByFactoryId(FactoryId){...}

...will call a stored procedure which joins two tables.

I definitely do not want the user to join "MyDatabase.Widgets" and "MyDatabase.Factories" in LINQ, as the records could be in the hundreds of thousands for each table.

So my question is: is there a way to use the ORM designer, yet still enforce good practices? Or, would I have to discourage the use of LINQ in favor of hand-written functions to make sure people do not do this.

Thanks,

Roger

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 7:36 PM by Buu Nguyen

Great introduction, Scott.  I have a question, how would inheritance work with extension method?    For example you have extension method In() for class A, how can you have an enhanced version of In() for class B which is a subclass of A?  Thanks.

# re: New "Orcas" Language Feature: Extension Methods

Tuesday, March 13, 2007 10:36 PM by kevindente

Scott,

I'm referring to the guidance posted here:

http://blogs.msdn.com/vbteam/archive/2007/03/10/extension-methods-best-practices-extension-methods-part-6.aspx

"Think twice before extending types you don't own"

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 12:37 AM by Vikram

This is really very very cool.

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 1:53 AM by Kamran Shahid

Is Linq to sql is sql server specific or we can use it with any database {like mysql,oracle,msaccess e.t.c.}

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 5:15 AM by michielvoo

Scott, would you consider extending the IntelliSense for an extension method to display where the method originates?

# Will it also be possible to extend classes with new interface implementations?

Wednesday, March 14, 2007 7:16 AM by Wouter

Hi Scott, this seems like a really nice feature. Will it also be possible to extend classes with new interface implementations?

So could I do this:

public static class ScottGuExtensions : IFormattable

{

   public static string ToString(this bool b, string format, IFormatProvider formatProvider)

   {

       return "whatever";

   }

}

So that System.Boolean will now also implement IFormattable?

Would be strange to have a static class implement an interface though. But then again, it's also a bit strange that a static method of a static class will become a non-static method of another class...

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 7:34 AM by purpleblob

Remind me why we do OO ?

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 8:12 AM by Natasa Manousopoulou

Is it possible or doable to have generic extension methods? I.e.

static class Extension<T>

{

 public static bool In(this T s, IEnumerable<T> c)

 {

   foreach (T t in c)

     if (t.Equals(s))

       return true;

   return false;

 }

}

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 5:34 PM by Wim Hollebrandse

Great blog post Scott. You keep cranking them out, don't you?!

I think your example about extending string with IsEmailValidEmail address feels a bit wrong, as it's not extending anything purely string related, but specifically Internet e-mail addresses, which some apps would not need. Instead, things like IsNullOrEmpty() or some different uses/overloads of Join() feel more natural to me to extend the string class with. As is your second example to check for values in a collection, using In().

I realize you're giving an illustrative example, but think your second example is more in line with your cautious advice at the end. ;-)

Keep up the good work.

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, March 14, 2007 5:37 PM by Hainesy

Hi Scott

Nice post... seeing as this entirely handled by the compiler, can we reflect on an extension method at runtime?

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 15, 2007 1:23 AM by bonskijr

Hi Scott,

Aside from the intellisense indicating that it is an extension method, will the editor color code it also to differentiate it from object methods? One might get used to that method without being aware that it is one, then move to another computer and wonder why it doesn't appear in the intellisense.

Thanks,

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 15, 2007 1:56 AM by Robert McKee

Very nice.  This almost gives .NET the same capabilities as java's prototypes.  Almost.  If an extension name and a base class name are the same, unfortunately the way it currently stands, the base class method is executed instead of the extension, which I'd prefer if it was the other way around, but I understand just how complicated it would be to try and retrofit that in .NET now.  A nice compromise I guess, but still irks be that java's implementation is more powerful.

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 15, 2007 9:25 AM by Richard

Is it possible to define generic extension methods? For example, could your "In" method be defined as:

public static bool In<T>(this T o, IEnumerable<T> c)

{

   foreach (T i in c)

   {

       if (i.Equals(o))

           return true;

   }

   return false;

}

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 15, 2007 10:50 AM by Dag H. Baardsen

Nice introduction on a new concept. Also, this feature is another step towards SmallTalk'alizing C# - I guess the old folks had some good ideas that are now being more widespread and common :-)

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 15, 2007 6:21 PM by Josh Schwartzberg

Great article Scott.  I'm really looking forward to using all of the new language features.  So, when can we generally expect Orcas to be officially released? :)

# re: New "Orcas" Language Feature: Extension Methods

Friday, March 16, 2007 2:19 AM by ScottGu

Hi Josh,

Orcas will officially RTM the second half of this year.  We'll should have Beta1 out in the next month or so.

thanks,

Scott

# Time 2 used those silly tabs in intellisence½

Friday, March 16, 2007 2:20 AM by Nicolaj S. Lindtner

I can't help by saying that extension methods will make reviews harder. Especially will the learning curve of the basic framework methods be harder, as u will be led to believe the extension methods are part of framework.

I would suggest u made a new tab with the extension methods (so we no just have common and all).

Thx for a outstanding blog

# re: New "Orcas" Language Feature: Extension Methods

Friday, March 16, 2007 2:32 AM by ScottGu

Hi Kamran,

We'll have a provider model that allows you to connect to multiple backend databases when it is all done.  So it won't be SQL Server specific.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Friday, March 16, 2007 2:47 AM by ScottGu

Hi Roger,

The good news is that you can map/model stored procedures using LINQ to SQL really elegantly.  I think thi swill give you what you are after in terms of modelling your database.

I'll make sure to-do some blog posts on this in the weeks ahead.

Thanks,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Friday, March 16, 2007 2:48 AM by ScottGu

Hi Natasa,

Yes - you can definitely use generics for extension methods.  You would define them exactly as you have above:

public static bool In<T>(this T o, IEnumerable<T> c)

{

  foreach (T i in c)

  {

      if (i.Equals(o))

          return true;

  }

  return false;

}

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Friday, March 16, 2007 6:07 PM by Dave

I can't wait for extension methods.

public static IEnumerable<TAttribute> EachCustomAttribute<T, TAttribute>(this T o, bool inherit)

   where T : class

   where TAttribute : System.Attribute

{

   TAttribute[] list = (TAttribute[]) o.GetType().GetCustomAttributes(typeof(TAttribute), inherit);

   foreach(TAttribute attr in list)

       yield return attr;

}

# re: New "Orcas" Language Feature: Extension Methods

Saturday, March 17, 2007 2:26 AM by Zeeshan Hirani

How come i dont see the namespace for

System.Xml.Linq i am using the march ctp for 2007. Am i missing something. When i try to add a reference i dont see the dll for system.xml.linq

but i do see it installed in gac at

C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\2.0.0.0__b77a5c561934e089\System.Xml.Linq.dll

is anyone else having problems finding system.xml.linq namespace?

# re: New "Orcas" Language Feature: Extension Methods

Monday, March 19, 2007 2:15 AM by ScottGu

Hi Zeeshan,

Make sure you add the System.Core.dll assembly reference to your project.  I believe there also might be a separate assembly reference you'll want/need to add for the System.Xml.Linq assembly.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Monday, March 19, 2007 12:19 PM by James

Hi Scott,

Thanks for the great intro to these extensions and continued LINQ discussion.  I do have a question though.  From an OO perspective I don't see how this feature fits in. I mean, doesn't functionality like 'IsEmailAddress' really belong in a 'format checking' context like a StringFormat type class rather than being incorporated as a method of a primitive type?  I'm worried that by using these I may be potentially loosing some of the structure of my applications.

Thanks,

James

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 22, 2007 12:53 PM by Mark Hildreth

Scott,

I think the most obvious benefit is it will almost eliminate the use of helper classes/functions. Can properties be added to types in the same manner? Similarly, if you could implement "extension interfaces" such that you could add the methods and properties to sealed classes to make them implement a custom interface, this would be really powerful and reduce a lot of unnecessary method overloading and logic forks. Will these features also be available?

-Mark

# re: New "Orcas" Language Feature: Extension Methods

Monday, March 26, 2007 12:33 AM by ScottGu

Hi Mark,

The extension mechanism works for both interfaces and classes.

Right now you can only add extension methods (and not properties).  I know the team is considering adding properties in the future though.

Hope this helps,

Scott

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 29, 2007 1:46 PM by Vic

I agree with Wim Hollebrandse and James that your example string.IsEmailAddress() was a poor choice - it encourages bad programming style.  You have a lot of influence both within Microsoft and without, please take more care in selecting examples that promote good style.  The In() example was also questionable since the Framework already provides a Contains() method that does the same thing (maybe not as intuitively depending upon one's reading preferences).

While I love nearly all the new features that C# 3.0 and LINQ will introduce and the boost it will be to productivity, the new weapons will allow developers to not just shoot themselves in the foot, but to blow their whole leg off.

I hope the gains supplied from C# 3.0 and LINQ outweigh all the bad things developers will do with it and produce a sum total gain in overall code readability/usability.  Programmers will have to be that much more careful after this release.

# re: New "Orcas" Language Feature: Extension Methods

Thursday, March 29, 2007 2:00 PM by Vic

I know me earlier message may come across a little strongly and somewhat personal...  I only mean it as positive criticism and have a lot of respect for Scott in general and recommend his blog as a great source of information on ASP.NET, ASP.NET AJAX Library, and Visual Studio.

# re: New "Orcas" Language Feature: Extension Methods

Saturday, April 07, 2007 2:22 PM by MikeR

This is outstanding Scott! I am really looking forward to using LINQ in my current projects. Keep up the good work.

# re: New "Orcas" Language Feature: Extension Methods

Wednesday, April 18, 2007 11:08 AM by commenter

Extension methods are the straw that made the camel even more fun to program with.

# Tobias Gurock ??? tobias.feedian.com &raquo; Blog Archive &raquo; Learning C# 3.0

Pingback from  Tobias Gurock ??? tobias.feedian.com  &raquo; Blog Archive   &raquo; Learning C# 3.0

# Tobias Gurock - tobias.feedian.com &raquo; Blog Archive &raquo; What&#8217;s involved in a simple Linq query?

Pingback from  Tobias Gurock - tobias.feedian.com  &raquo; Blog Archive   &raquo; What&#8217;s involved in a simple Linq query?

# Extension methods are gonna be fun!

So I've had a (very) small amount of time to play around with Orcas and Silverlight, but some of the

# Ruby-Like Syntax in C# 3.0

Thursday, May 24, 2007 6:35 PM by you've been HAACKED

Ruby-Like Syntax in C# 3.0

# Ruby-Like Syntax in C# 3.0

Thursday, May 24, 2007 6:52 PM by Community Blogs

Scott Hanselman recently wrote a post about how Ruby has tits or is the tits or something like that.

# The Ruby Way &raquo; Ruby Like Expressiveness in C# 3.0

Saturday, May 26, 2007 11:30 PM by The Ruby Way » Ruby Like Expressiveness in C# 3.0

Pingback from  The Ruby Way &raquo; Ruby Like Expressiveness in C# 3.0

# C# Extension methods

Saturday, June 02, 2007 3:45 AM by C# Extension methods

Pingback from  C# Extension methods

# LINQ to SQL (Part 3 - Querying our Database)

Friday, June 29, 2007 5:14 AM by Blogs

Last month I started a blog post series covering LINQ to SQL. LINQ to SQL is a built-in O/RM (object

# Code shots: Deferred Query Evaluation

Monday, July 02, 2007 6:48 AM by Technoeuphoria!

It&#39;s important to note that when you use Linq, language integrated queries, the values are actually

# Extension Methods, a Simple HowTo

Sunday, July 08, 2007 11:11 AM by Derik Whittaker

I finally got around to installing Orcas on my laptop this weekend. You are probably asking yourself,

# Utility Methods - Are They The Devil?

Tuesday, July 17, 2007 1:19 AM by Palermo4

Awhile back I posted a blog on string comparisons . The number of comments on that blog also spawned

# Lo nuevo de C# 3.0 (5 de n): más métodos de extensión

Friday, July 20, 2007 1:18 AM by .NET a 2.860 m de altura

En nuestra primera entrada sobre m&eacute;todos de extensi&oacute;n, Athenian preguntaba si hab&iacute;a

# Christian Liensberger » Blog &raquo; string.Reverse and C# 2.0 vs C# 3.0

Pingback from  Christian Liensberger » Blog &raquo; string.Reverse and C# 2.0 vs C# 3.0

# Extension Methods in C# 3.0

Thursday, August 02, 2007 4:51 PM by Ian Suttle's Blog

Extension Methods in C# 3.0

# Adventures in .NET 3.5 Part 1

Saturday, August 04, 2007 2:00 AM by Alex Hoffman

A "Print" To the Console Because I write a lot of small console applications, I find myself typing .

# Using LINQ to XML (and how to build a custom RSS Feed Reader with it)

Tuesday, August 07, 2007 10:34 AM by Blogs

One of the big programming model improvements being made in .NET 3.5 is the work being done to make querying

# My First C# 3.0 Program

Thursday, August 09, 2007 3:41 PM by Doron's .NET Space

I've finally decided to download the new &quot;Orcas&quot; CTP of Visual Studio , which includes support

# fluxcapacity &raquo; Blog Archive &raquo; Searching for close matches in C#

Pingback from  fluxcapacity  &raquo; Blog Archive   &raquo; Searching for close matches in C#

# Type Extensions | Aaron Lerch

Thursday, August 23, 2007 8:15 AM by Type Extensions | Aaron Lerch

Pingback from  Type Extensions | Aaron Lerch

# Want to learn LINQ? Learn some of the new language features first - it will pay off.

Tuesday, August 28, 2007 10:09 AM by MSDN Ireland Blog

As you can probably tell from the title of my last few posts I've been doing some work with LINQ over

# Want to learn LINQ? Learn some of the new language features first - it will pay off.

Tuesday, August 28, 2007 10:09 AM by Ronan Geraghty's Weblog

As you can probably tell from the title of my last few posts I've been doing some work with LINQ over

# Code shots: Deferred Query Evaluation

Saturday, September 01, 2007 1:43 AM by Jocelyn World

It&#39;s important to note that when you use Linq, language integrated queries, the values are actually

# Want to learn LINQ? Learn some of the new language features first - it will pay off.

Monday, September 03, 2007 10:46 AM by .: Stefan Gabriel Georgescu's blog :.

As you can probably tell from the title of my last few posts I've been doing some work with LINQ over

# ASP.NET Centric Extensions

Wednesday, September 19, 2007 7:04 PM by Starin' at the Wall 2.0

ASP.NET Centric Extensions

# &nbsp; C# 3.5 Conversion Extension Method Library 1.0&nbsp;by&nbsp;j-dee.com

Pingback from  &nbsp; C# 3.5 Conversion Extension Method Library 1.0&nbsp;by&nbsp;j-dee.com

# Six Custom .NET String Manipulation Functions / Methods for Everyday Use

Thursday, September 20, 2007 10:56 AM by Troy DeMonbreun

Six Free Custom .NET String Manipulation Functions / Methods for Everyday Use

# links for 2007-03-15 : The Mailowl Scrolls

Thursday, September 27, 2007 12:17 AM by links for 2007-03-15 : The Mailowl Scrolls

Pingback from  links for 2007-03-15 : The Mailowl Scrolls

# Extension Methods er the SHIT!

Thursday, September 27, 2007 3:05 PM by slyngelstat.dk

Extension Methods er the SHIT!

# Extension methods in Powershell

Friday, September 28, 2007 5:02 PM by Claudio Brotto

Ho questo post di Bart De Smet nella lista delle &quot;Review&quot; da qualche giorno, ci avevo dato

# C# 3.0: Extension Methods

Sunday, September 30, 2007 6:39 AM by Noticias externas

Extension Methods er en af de nye grundlæggende sprogudvidelser der kommer med C# 3.0. Extension methods

# MSDN Blog Postings &raquo; C# 3.0: Extension Methods

Sunday, September 30, 2007 9:22 AM by MSDN Blog Postings » C# 3.0: Extension Methods

Pingback from  MSDN Blog Postings  &raquo; C# 3.0: Extension Methods

# Useful managed HTML DOM methods for Microsoft Silverlight

Sunday, September 30, 2007 7:02 PM by Jeff Wilcox's Blog on Microsoft UIFx

In the versions of Microsoft Silverlight that have been released to date, the managed HTML DOM interfaces

# Useful managed HTML DOM methods for Microsoft Silverlight

Sunday, September 30, 2007 7:33 PM by Noticias externas

In the versions of Microsoft Silverlight that have been released to date, the managed HTML DOM interfaces

# MSDN Blog Postings &raquo; Useful managed HTML DOM methods for Microsoft Silverlight

Pingback from  MSDN Blog Postings  &raquo; Useful managed HTML DOM methods for Microsoft Silverlight

# Mowdolwis.Com &raquo; MSDN Blog Postings ?? Useful managed HTML DOM methods for Microsoft &#8230;

Pingback from  Mowdolwis.Com &raquo; MSDN Blog Postings ?? Useful managed HTML DOM methods for Microsoft &#8230;

# microsoft &raquo; MSDN Blog Postings ?? Useful managed HTML DOM methods for Microsoft &#8230;

Pingback from  microsoft &raquo; MSDN Blog Postings ?? Useful managed HTML DOM methods for Microsoft &#8230;

# Useful managed HTML DOM methods for Microsoft Silverlight : Celebrity News Corner

Pingback from  Useful managed HTML DOM methods for Microsoft Silverlight : Celebrity News Corner

# Xbox &raquo; Useful managed HTML DOM methods for Microsoft Silverlight

Pingback from  Xbox &raquo; Useful managed HTML DOM methods for Microsoft Silverlight

# Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5

Tuesday, October 02, 2007 1:33 AM by ScottGu's Blog

Earlier this year I blogged about a new language extensibility feature of C# and VB called "Extension

# ÜberUtils - Part 1 : Cryptography

Tuesday, October 02, 2007 5:19 PM by BradVin's .Net Blog

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New",

# Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5

Wednesday, October 03, 2007 11:00 PM by ASPInsiders

Earlier this year I blogged about a new language extensibility feature of C# and VB called "Extension

# Extension Methods in C# 3.0 + Fluent Interface = Ruby-like syntax.

Friday, October 05, 2007 5:23 PM by Troy DeMonbreun

Attain Ruby-like date syntax with C# 3.0 Extension Methods and Fluent Interface

# Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5

Sunday, October 07, 2007 10:48 PM by Kelvin Zhang

Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5

# Introduction to LINQ Part 3 - Focus on new Syntax Concepts - Part 1 - Extension Methods

Wednesday, October 10, 2007 9:41 AM by Jason Farrell

Introduction to LINQ Part 3 - Focus on new Syntax Concepts - Part 1 - Extension Methods

# Post MSDN Tech Talk: Introduction to Language Integrated Query

Tuesday, October 16, 2007 4:49 AM by Technoeuphoria!

Okay, I didn&#39;t have any slides today, and I redirected people to this blog this morning. So allow

# Visual Studio 2008 and .NET 3.5 Released

Monday, November 19, 2007 1:53 PM by Blogs

Today we shipped Visual Studio 2008 and .NET 3.5. You can download the final release using one of the

# A Public Call for C# Extension Method Best Practices

Tuesday, November 20, 2007 12:04 AM by Chad Myers' Blog

A Public Call for C# Extension Method Best Practices

# Extension methods in .NET3.5 and LINQ

Tuesday, November 20, 2007 5:12 AM by Merrick Chaffer's Blog

Was just reading on Scott Gu&#39;s blog about the release of Visual Studio 2008 and .NET 3.5, and came

# Neues .NET 3.5 Feature: Extension Methods

Tuesday, November 20, 2007 1:19 PM by Jürgen Gutsch

Die erste interessante Spracherweiterung in .NET 3.5 die ich hier beschreiben möchte, ist die Extension

# To LINQ or not to LINQ

Tuesday, November 27, 2007 9:44 AM by Rodrigo Guerreiro

To LINQ or not to LINQ

# New in VS 2008 and .NET 3.5 at iceeer

Tuesday, November 27, 2007 12:27 PM by New in VS 2008 and .NET 3.5 at iceeer

Pingback from  New in VS 2008 and .NET 3.5 at  iceeer

# Debriefing del Briefing Online

Friday, November 30, 2007 10:25 AM by Miguel Saez

Seg&#250;n wikipedia: A debriefing or psychological debriefing is a one-time, semi-structured conversation

# Debriefing del Briefing Online

Friday, November 30, 2007 11:11 AM by Noticias externas

Seg&#250;n wikipedia: A debriefing or psychological debriefing is a one-time, semi-structured conversation

# Duck Typing Saves You Some Typing

Monday, December 03, 2007 8:35 PM by .tyler

Duck Typing Saves You Some Typing

# Cannot Debug Unit Tests in VS 2008

Wednesday, December 12, 2007 10:37 PM by Jeff Handley

Cannot Debug Unit Tests in VS 2008

# Extension methods and primitive obsession

Tuesday, December 18, 2007 5:29 PM by GrabBag

In another water-cooler argument today, a couple of coworkers didn&#39;t like my extension method example

# Internal DSLs, fluent interfaces and extension methods in C#

Thursday, December 20, 2007 8:06 AM by Weblog :: Boris Ševo

This is one of my longest blog posts and because of that I will start with a short list which describes

# Internal DSLs, fluent interfaces and extension methods in C#

Thursday, December 20, 2007 9:58 AM by Weblog :: Boris Ševo

This is one of my longest blog posts and because of that I will start with a short list which describes

# Generic extension methods are way to cool!

Friday, December 21, 2007 6:18 AM by Community Blogs

Extension Methods If you don't know extension methods yet, please have a look at this blogpost of our

# Cool C# 3.0 Extension Method Idea

Sunday, December 23, 2007 4:57 PM by Page Brooks

Cool C# 3.0 Extension Method Idea

# Sheepoff.Com &raquo; Cool C# 3.0 Extension Method Idea

Monday, December 24, 2007 1:40 AM by Sheepoff.Com » Cool C# 3.0 Extension Method Idea

Pingback from  Sheepoff.Com &raquo; Cool C# 3.0 Extension Method Idea

# LINQ - Part 1 - the new querying enhancement to C# and VB.Net

Monday, December 31, 2007 3:44 AM by Manjula's Blog

Overview I thought of gathering some information about Microsoft&#39;s latest querying technology and

# ListItemCollection.SelectByValue, SelectByText

Wednesday, January 09, 2008 6:45 PM by Danie Bruwer

I found a very easy way to select items in a ListItemCollection using Extension Methods and Anonymous

# ListItemCollection.SyncToList

Wednesday, January 09, 2008 7:16 PM by Danie Bruwer

Here&#39;s a example that uses extension methods , lambda expressions and anonymous methods to synchronize

# Generic extensions methods to the rescue

Friday, January 25, 2008 10:40 AM by Wesley Bakker

[note: This is a repost from my previous blogspace. My previous blogspace has been out of air for a while

# String.IsNullOrEmpty as Extension Method

Friday, January 25, 2008 5:34 PM by Thomas Freudenberg

Most you will probably know about Extension Method introduced with C# 3.0. If not, I stringly recommend

# Custom User Input Validation in WPF

Monday, January 28, 2008 1:39 AM by Infosys | Microsoft

How to do user input validation in WPF without doing DataBinding

# journal.stuffwithstuff.com &raquo; Blog Archive &raquo; C# Extension Methods: Not Just for Breakfast

Pingback from  journal.stuffwithstuff.com  &raquo; Blog Archive   &raquo; C# Extension Methods: Not Just for Breakfast

# Extensively using extension methods &laquo; AJ&#8217;s blog

Sunday, February 10, 2008 8:27 AM by Extensively using extension methods « AJ’s blog

Pingback from  Extensively using extension methods &laquo; AJ&#8217;s blog

# Useful managed HTML DOM methods for Microsoft Silverlight - Jeff Wilcox

Pingback from  Useful managed HTML DOM methods for Microsoft Silverlight - Jeff Wilcox

# Hacker Wannabe &raquo; Blog Archive &raquo; Durere ??i limbaje de programare

Pingback from  Hacker Wannabe  &raquo; Blog Archive   &raquo; Durere ??i limbaje de programare

# .Sitecore &raquo; Blog Archive &raquo; C# 3.0: Extension Methods + Resharper 4: EAP

Pingback from  .Sitecore  &raquo; Blog Archive   &raquo; C# 3.0: Extension Methods + Resharper 4: EAP

# Saber si una cadena está vacía usando métodos de extensión (C#/VB.Net)

Sunday, February 24, 2008 3:07 PM by Variable not found, 0:1

Hace unos meses comentaba las distintas opciones para saber si una cadena está vacía en C# , y la conclusión

# Extension Methods | Cornel&#8217;s Blog

Tuesday, February 26, 2008 9:04 AM by Extension Methods | Cornel’s Blog

Pingback from  Extension Methods |  Cornel&#8217;s Blog

# Avoiding a Base Page In ASP.Net

Friday, February 29, 2008 2:12 AM by Hilton Giesenow's Jumbled Mind

I blogged a while ago about how I&#39;m not comfortable with using a base class that all of your pages

# Cool TrimText Extension Method for TextBox

Monday, March 03, 2008 3:13 AM by Technology

Extension Methods are one of the most powerful features of .NET 3.5 and they can add a lot of flexibility

# Extension Methods - TehWorld Blog

Sunday, March 16, 2008 5:48 PM by Extension Methods - TehWorld Blog

Pingback from  Extension Methods -  TehWorld Blog

# Working with Virtual Machines in PowerShell, SCVMM and C#

Monday, March 17, 2008 3:09 PM by DDITDev

Lately I've been experimenting with SCVMM and PowerShell, and I wondered how hard it would be to automate

# Algumas Id??ias &raquo; Blog Archive &raquo; Extension Methods

Wednesday, March 26, 2008 7:04 PM by Algumas Id??ias » Blog Archive » Extension Methods

Pingback from  Algumas Id??ias  &raquo; Blog Archive   &raquo; Extension Methods

# Algumas Id??ias &raquo; Blog Archive &raquo; Extension Methods

Wednesday, March 26, 2008 8:18 PM by Algumas Id??ias » Blog Archive » Extension Methods

Pingback from  Algumas Id??ias  &raquo; Blog Archive   &raquo; Extension Methods

# Template Delegate Pattern

Thursday, March 27, 2008 5:41 PM by GrabBag

This post was originally published here . I&#39;ve had to use this pattern a few times, most recently

# Constrained generic extension methods

Thursday, March 27, 2008 6:09 PM by GrabBag

This post was originally published here . When I first saw extension methods, a new feature in C# 3.0

# ExtensionAttribute Visual Studio Item Template - Waldek Mastykarz

Pingback from  ExtensionAttribute Visual Studio Item Template - Waldek Mastykarz

# ExtensionMethods - flavorful syntactic sugar

Friday, April 04, 2008 2:23 PM by ExtensionMethods - flavorful syntactic sugar

Pingback from  ExtensionMethods - flavorful syntactic sugar

# ExtensionMethods - flavorful syntactic sugar

Monday, April 07, 2008 9:36 AM by James Manning's blog

A potential place to use an extension method cropped up in our team this week, and I gave feedback that

# Simple extension methods to help with Asserting values

Thursday, April 10, 2008 8:49 AM by Derik Whittaker

In the past I have written about the Fail Fast principle.&#160; This is a principle I try to live my

# Turn DataTable object into a styled HTML table using extension methods in C#

Monday, April 28, 2008 4:09 PM by Janko At Warp Speed

Turn DataTable object into a styled HTML table using extension methods in C#

# Dot Net 3.0 Cool Feature &laquo; Neerajtrivedi&#8217;s Weblog

Tuesday, July 08, 2008 2:38 AM by Dot Net 3.0 Cool Feature « Neerajtrivedi’s Weblog

Pingback from  Dot Net 3.0 Cool Feature &laquo; Neerajtrivedi&#8217;s Weblog

# language features

Tuesday, July 08, 2008 11:23 AM by language features

Pingback from  language features

# HowTo: Generische Extensions | Code-Inside Blog

Tuesday, July 08, 2008 3:07 PM by HowTo: Generische Extensions | Code-Inside Blog

Pingback from  HowTo: Generische Extensions | Code-Inside Blog

# “Orcas”新语言特征 :Lambda (λ) 表达式

Thursday, July 10, 2008 1:33 AM by 徐文兵

“Orcas”新语言特征 :Lambda (λ) 表达式

# Closures and Linq in C# 3.5

Sunday, July 20, 2008 11:49 PM by jakelite

Keith posted a great article demonstrating Linqs capabilities. There he was asked if his examples where

# Closures and Linq in C# 3.0

Wednesday, July 23, 2008 11:21 PM by jakelite

Keith posted a great article demonstrating Linqs capabilities. There he was asked if his examples where

# types of ducks

Tuesday, August 05, 2008 11:24 PM by types of ducks

Pingback from  types of ducks

# Utiliser LINQ to SQL (Partie 1) par Scott Guthrie

Wednesday, August 27, 2008 10:49 AM by Blog-Microsoft.fr

Utiliser LINQ to SQL (Partie 1) par Scott Guthrie

# NCZOnline - The Official Web Site of Nicholas C. Zakas &raquo; Blog Archive &raquo; .NET to be more like JavaScript

Pingback from  NCZOnline - The Official Web Site of Nicholas C. Zakas  &raquo; Blog Archive   &raquo; .NET to be more like JavaScript

# Extension Properties

Wednesday, September 10, 2008 7:05 AM by Code Beside

Extension Properties

# ASP.NET MVC Archived Buzz, Page 1

Wednesday, September 24, 2008 11:20 PM by ASP.NET MVC Archived Buzz, Page 1

Pingback from  ASP.NET MVC Archived Buzz, Page 1

# LINQ Extension Methods and Lambda Expressions in SharePoint 2007 Development

Saturday, September 27, 2008 2:40 AM by Oscar Medina's Blog

LINQ Extension Methods and Lambda Expressions in SharePoint 2007 Development

# Turn DataTable object into a styled HTML table using extension methods in C#

Monday, October 06, 2008 6:54 AM by Janko At Warp Speed

Turn DataTable object into a styled HTML table using extension methods in C#

# Watermarked TextBox in Windows Forms on .NET

Wednesday, November 05, 2008 5:36 PM by Bite my bytes

Watermarked TextBox in Windows Forms on .NET

# Watermarked TextBox in Windows Forms on .NET

Wednesday, November 05, 2008 6:09 PM by Zunanji viri

Phew! It&#39;s been a while since I posted some code here! Here goes... I had a modest request from a

# New &#8220;Orcas&#8221; Language Feature: Extension Methods &laquo; using &#8230;

Pingback from  New &#8220;Orcas&#8221; Language Feature: Extension Methods  &laquo; using &#8230;

# Lambda One-Liner or LINQ

Monday, December 01, 2008 11:57 PM by using System.Blog.Code;

Lambda One-Liner or LINQ

# Code shots: Deferred Query Evaluation

Wednesday, December 17, 2008 5:38 AM by Jocelyn

It&#39;s important to note that when you use Linq, language integrated queries, the values are actually

# SharePoint 2007 : Extension Method (TryGet)

Thursday, December 18, 2008 9:56 AM by Philippe Sentenac [MVP SharePoint]

Ca fait un moment que je tripatouillais ca dans ma tete, il est temps que je vous en parle : L'utilisation

# Visual Studio 2008: What's new in the language?

Thursday, December 18, 2008 10:47 PM by Jocelyn

I&#39;ve been following Scott Gu&#39;s blog for news on what&#39;s new in Orcas. He has a &quot;New in

# Code shots: Deferred Query Evaluation

Tuesday, January 06, 2009 6:59 AM by jocelyn

It&#39;s important to note that when you use Linq, language integrated queries, the values are actually

# Visual Studio 2008: What's new in the language?

Wednesday, January 07, 2009 12:59 AM by jocelyn

I&#39;ve been following Scott Gu&#39;s blog for news on what&#39;s new in Orcas. He has a &quot;New in

# Typesafe ICriteria using Lambda Expressions

Wednesday, January 07, 2009 1:21 PM by NHibernate blog

Originally announced on my own blog here: Using Lambda Expressions with NHibernate Introduction I love

# C#/VB.NET: Extension Methods

Tuesday, January 20, 2009 7:15 PM by Chris Pietschmann

C#/VB.NET: Extension Methods

# XQuery, SSIS, InfoPath, LINQ, C# 3.0, and a Partridge in a Pear Tree &laquo; DevExpertise

Pingback from  XQuery, SSIS, InfoPath, LINQ, C# 3.0, and a Partridge in a Pear Tree &laquo; DevExpertise

# Background: Extension Methods, Silverlight & Linq

Saturday, February 07, 2009 1:04 PM by Jesse Liberty - Silverlight Geek

&#160; A number of articles I've read recently have mentioned &quot;Extension methods&quot; in passing

# Background: Extension Methods, Silverlight & Linq

Saturday, February 07, 2009 1:45 PM by Microsoft Weblogs

&#160; A number of articles I've read recently have mentioned &quot;Extension methods&quot; in passing

# Silverlight Travel &raquo; Background: Extension Methods, Silverlight &#038; Linq

Pingback from  Silverlight Travel &raquo; Background: Extension Methods, Silverlight &#038; Linq

# Cloning Object Properties via Reflection &laquo; {Programming} &amp; Life

Pingback from  Cloning Object Properties via Reflection &laquo; {Programming} &amp; Life

# Programming with Silverlight, WPF &amp; .NET &raquo; Extension Methods, Silverlight &#038; Linq

Pingback from  Programming with Silverlight, WPF &amp; .NET &raquo; Extension Methods, Silverlight &#038; Linq

# C# .NET Extension Methods 3.0 |

Monday, February 16, 2009 12:33 PM by C# .NET Extension Methods 3.0 |

Pingback from  C# .NET Extension Methods 3.0 |

# Nested Master Pages and Null Reference exception | tech tips

Pingback from  Nested Master Pages and Null Reference exception | tech tips

# PLINQ (PFX) o LINQ en paralelo. &laquo; THE .NET WAY

Thursday, April 16, 2009 5:36 AM by PLINQ (PFX) o LINQ en paralelo. « THE .NET WAY

Pingback from  PLINQ (PFX) o LINQ en paralelo. &laquo; THE .NET WAY

# Enum description using reflection and extension methods &laquo; Joe Stevens&#039;s Blog

Pingback from  Enum description using reflection and extension methods &laquo;  Joe Stevens&#039;s Blog

# Redirect301 &laquo; C&amp;M Blog

Monday, June 22, 2009 5:24 PM by Redirect301 « C&M Blog

Pingback from  Redirect301 &laquo; C&amp;M Blog