Functional Flow

Extension Properties

| Comments

After you start to use extension methods and see all their benefits, you start thinking about how nice it would be to also have extension properties. When Scott Guthrie first announced them in New "Orcas" Language Feature: Extension Methods, someone immediately asked about extension properties. It just seems the feature is incomplete without both.

One particular area that would benefit greatly from extension properties would be WPF. Every time you define an attached property, you usually create a static getter and a static setter for it. If you could package that up in an extension property, attached properties would be much nicer to use.

There have been some hints that the C# language team is considering extension properties for the future, so maybe we'll get them in C# 4.0. But if you don't want to wait until 2010, you can have extension properties right now if you use F#. Check out Matthew Podwysocki's Object Oriented F# - Extension Everything.

Comments