Extension Methods

Top  Previous  Next


Clarion.Net supports using and declaring extension methods. To declare extension methods use the Extension attribute.


Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in Clarion#, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.


The most common extension methods are the LINQ (Language Integrated Query) standard query operators that add query functionality to the existing System.Collections.IEnumerable and System.Collections.Generic.IEnumerable types. To use the standard query operators, first bring them into scope with a using System.Linq directive. Then any type that implements IEnumerable appears to have instance methods such as GroupBy, OrderBy, Average, etc.


LINQ support requires that you have Net Framework 3.5 installed.

The System.Core assembly and the corresponding USING statements are needed for the [Extension] attribute.





   USING System.Linq

   USING System.Core

   USING System.Collections.Generic

   USING System.Runtime.CompilerServices