Extension method
In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method declared in the type definition.
Eric Lippert, a principal developer on the C# compiler team, says "Extension methods certainly are not object-oriented.".
Support in programming languages
Extension methods are features of numerous languages including C#, Gosu, Javascript, Oxygene, Ruby, Smalltalk and Visual Basic.NET.
In VB.NET and Oxygene, they are recognized by the presence of the "extension
" keyword or attribute.
In C# they're implemented as static methods in static classes, with the first argument being of extended class and preceded by "this" keyword.
In Smalltalk, any code can add a method to any class at any time, by sending a method creation message (such as methodsFor:
) to the class the user wants to extend. The Smalltalk method category is conventionally named after the package that provides the extension, surrounded by asterisks. For example, when Etoys application code extends classes in the core library, the added methods are put in the *etoys*
category.