User Tools

Site Tools


extension_methods.htm
Navigation:  Clarion.Net (Clarion#) > Clarion# Language Extensions > LINQ Support >====== Extension Methods ====== Previous pageReturn to chapter overviewNext page

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.

NoteBox.jpg

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.

Example:

  PROGRAM

   USING System.Linq

   USING System.Core

   USING System.Collections.Generic

   USING System.Runtime.CompilerServices

   NAMESPACE qq

[Extension]

dd CLASS,STATIC,PUBLIC

[Extension]

mm PROCEDURE(SIGNED aa),STATIC,PUBLIC

extension_methods.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1