Show/Hide Toolbars

XSharp

NoteThis command is only available in the Xbase++ dialect

Purpose

Declare and implement methods for a class, both for instances and the class itself

Syntax

 Method forward declaration

 [Modifiers] METHOD <MethodName,...> [IS <MethodName>] [IN <SuperClass>]

 

 Access/Assign method forward declaration

 [Attributes] ACCESS ASSIGN [CLASS] METHOD <MethodName> [VAR <VarName>] [AS <idType>]

 [Attributes] ACCESS | ASSIGN [CLASS] METHOD <MethodName> [VAR <VarName>] [AS <idType>]

 

 Method inline declaration

 [Attributes] INLINE [CLASS] METHOD <MethodName>[ [([<idParam> [AS|REF|OUT|IN <idType>] [, ...])] ) [AS <idType>]
 [=> <expression>]
 CRLF

 [<Body>]
 [END METHOD]

Arguments

AttributesAn optional list of one or more attributes that describe meta information for am entity, such as for example the [TestMethod] attribute on a method/function containing tests in a MsTest class library. Please note that Attributes must be on the same line or suffixed with a semi colon when they are written on the line above that keyword.

 

ModifiersAn optional list of modifiers that specify the visibility or scope of the entity, such as PUBLIC, PROTECTED, HIDDEN, INTERNAL, SEALED, ABSTRACT or STATIC.

 

<MethodName,...> is a comma separated list with the names of the instance methods being declared. The name for a method follows the same convention as function and variable names. It must begin with a underscore or a letter and must contain alpha numeric characters.

 

IS <MethodName>The IS methodname clause is not supported by X#

 

IN <SuperClass>The IN Superclass clause is not supported (and not needed) by X#

 

AttributesAn optional list of one or more attributes that describe meta information for am entity, such as for example the [TestMethod] attribute on a method/function containing tests in a MsTest class library. Please note that Attributes must be on the same line or suffixed with a semi colon when they are written on the line above that keyword.

 

CLASSOptional modifier that specify that the declaration is for a class level method or class level property

 

ACCESS ASSIGNDeclares a Get/Set method for a property. You can to use one or both of these keywords.

 

<VarName>The Get/Set method may have a different name than the property that they implement.

 

AS <idType>Specifies the data type.  If omitted, then depending on the compiler options the type will be either USUAL or determined by the compiler.

 

INLINESpecifies that the whole method is included between the CLASS .. ENDCLASS keywords (other methods are so called forward declarations)

 

<idParam>A  parameter variable.  A variable specified in this manner is automatically declared local.  These variables, also called formal parameters, are used to receive arguments that you pass when you call the entity.

 

AS | REF|OUT|IN <idType>Specifies the data type of the parameter variable (called strong typing).  AS indicates that the parameter must be passed by value, and REF indicates that it must be passed by reference with the @ operator. OUT is a special kind of REF parameter that does not have to be assigned before the call and must be assigned inside the body of the entity. IN parameters are passed as READONLY references.
The last parameter in the list can also be declared as PARAMS <idType>[] which will tell the compiler that the function/method may receive zero or more optional parameters.
Functions or Methods of the CLIPPER calling convention are compiled to a function with a single parameter that this declared as Args PARAMS USUAL[]
 

 

=> <Expression>Single expression that replaces the multiline body for the entity. CANNOT be compiled with a body

 

<Body>Program statements that form the code of this entity.
The <Body> can contain one or more RETURN statements to return control to the calling routine and to serve as the function return value.  If no return statement is specified, control passes back to the calling routine when the function definition ends, and the function will return a default value depending on the return value data type specified (NIL if the return value is not strongly typed).
CANNOT be combined with an Expression Body

 

END METHODOptional end clause to indicate the end of the inline METHOD entity

Note

The visibility of a method is determined by the visibility attribute set with one of the statements EXPORTED:, PROTECTED:, HIDDEN: or INTERNAL:

 

Special method Names

In Xbase++ there are some reserved method names:

 

InitThis is the name of the constructor
InitClassThis is the name of the class constructor.

 

The implementation of constructors in .Net is somewhat different from Xbase++.

Therefore the class constructor cannot have any parameters.

The parameters of the Init() method become the constructor parameters.