The invocation operator is used to call a method.
invocation-expression:
primary-expression [< type-listopt >] ( argument-listopt )
The primary expression in the invocation operator must be a method group or a delegate type value. If the primary expression is a method group, the invocation operator invokes a method. If the primary expression is a delegate value, the invocation operator invokes a delegate. Otherwise, a compile error occurs.
An optional argument list presents values or variable references to be passed as method parameter values. Argument list is specified in round brackets. If there are no arguments, empty brackets are specified.
The language supports universal methods invocation. The optional list of parameter types must include all types assigned to be used in the invoked method. The list of parameter types is enclosed in angle brackets.
NOTE: The current implementation supports invocation of universal methods implemented using other programming languages and stored in imported libraries. The Fore.NET language does not support universal method development.
The result of the invocation operator is classified as follows:
If the invocation-expression invokes a method or delegate that returns void, the result is an empty expression. Such an expression cannot be an operand of any operator, and is permitted only in the context of an invocation statement.
Otherwise, the result is a value of the type returned by the method or delegate.
For a method invocation, the primary expression of the invocation operator must be a method group. The method group identifies the one method to invoke or the set of overloaded methods, from which to choose a specific method to invoke. In the latter case, determination of the specific method to invoke is based on the context provided by the types of the arguments in the argument list.
The compile-time processing of a method invocation of the form M(A), where M is a method group and A is an optional argument list, consists of the following steps:
A set of candidate methods is constructed. Starting with the set of methods associated with M, which were found by a previous member lookup, the set is reduced to those methods that are applicable with respect to the argument list A. The set reduction consists of applying the following rules to each method T.N in the set, where T is the type, in which the method N is declared:
If N is not applicable with respect to A, N is removed from the set.
If N is applicable with respect to A, all methods declared in a base type of T are removed from the set.
If the output set of candidate methods is empty, no applicable methods exist, and a compile error occurs.
The best method of the set of candidate methods is identified using the overloaded names resolution rules. If a single best method cannot be identified, the method invocation is ambiguous, and a compile error occurs.
For a delegate invocation, the primary expression of the invocation operator must be a value of a delegate type. Moreover, considering the delegate type to be a function member with the same parameter list as the delegate type, the delegate type must be applicable with respect to the argument list of the invocation operator.
The runtime processing of a delegate invocation of the form D(A), where D is a primary expression of a delegate type and A is an optional argument list, consists of the following steps:
D is calculated. If this evaluation causes an exception, invocation processing is stopped.
The value of D is checked. If the value of D is Null, System.NullReferenceException class exception is raised, and no further steps are executed.
Otherwise, D is a reference to a delegate instance. Function member invocations are executed on each of the callable elements in the invocation list of the delegate.
See also: