Extension Methods
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
New in .NET 3.5.
Extension methods are static methods that extend another class. The compiler and IDE will make it look like they're part of that class and show up as instance methods on any member of the target type. Extension methods are useful to add additional features to existing classes. They cannot be used to change the behavior of existing classes. If there is a method with the same signature already defined on the original type itself, the extension method is hidden, however different signatures with the same name does work.
Using Extension Methods
Extension methods have to be defined in a class with an [Extension] attribute on them. The namespace this extension class is defined in has to be in the uses list of the code that uses it. The new 3.5 runtime comes with System.Core.dll that provides several extension methods for the IEnumerable<T> interface exposing functions like searching for a subset, returning the first or last element and grouping them.
Writing Extension Methods
See Extension Methods (Writing) for information on writing extension methods.
LINQ and Extension Methods
LINQ doesn't have a hardcoded set of classes it uses for the methods that are called when using LINQ operations on something. Instead it tries to find a method or extension method on the class matching the name. For example: a where condition tries to call a method called "Where", select calls "Select". This approach makes it possible to use LINQ on any kind of class as long as there are extension methods for it.
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To