Finally found a good use for C# 3.0 Extension methods

I think of Extension methods as mostly a hack introduced so that the LINQ team could implement all their cool features without touching the core .Net dlls.

Here's a use of extension methods I can get behind though:

www.leastprivilege.com - Extension Methods for AntiXss

image

Published 20 March 08 04:14 by joshzana

Comments

# the core said on March 20, 2008 12:19 AM:

PingBack from http://tvnewsmag.com/thecore.html

# MichaelGG said on March 20, 2008 3:06 AM:

Yea, extension methods are unfortunate. An F# style pipeline operator (|>) is what was really needed for infix semantics. Combined with the ability to import classes (so their functions become in scope), you'd be able to write:

input |> HtmlEncode

The benefit is that you're not limited in which methods you can use. You'd be able to use any method, not just specially marked "extensions". It's also clear exactly what you're doing.

Maybe for C# 4 we'll get some cleaner, less "LINQ" focused, more general, improvements.

# joshzana said on March 27, 2008 10:10 PM:

Agreed, the biggest headache with extension methods for me is remembering to add a using statement.

Anonymous comments are disabled

Search

This Blog

Syndication

Page view tracker