Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 2.84 KB

ii.15.4-defining-methods.md

File metadata and controls

59 lines (37 loc) · 2.84 KB

II.15.4 Defining methods

MethodHeader ::=
MethAttr* [ CallConv ] Type [ marshal '(' [ NativeType ] ')' ] MethodName [ '<' GenPars '>' ] '(' Parameters ')' ImplAttr*

The method head (see also §II.10) consists of

  • the calling convention (CallConv, see §II.15.3)

  • any number of predefined method attributes (MethAttr, see §II.15.4.1.5)

  • a return type with optional attributes

  • optional marshalling information (§II.7.4)

  • a method name

  • optional generic parameters (when defining generic methods, see §II.10.1.7)

  • a signature

  • and any number of implementation attributes (ImplAttr, see §II.15.4.3)

Methods that do not have a return value shall use void as the return type.

MethodName ::=
.cctor
| .ctor
| DottedName

Method names are either simple names or the special names used for instance constructors and type initializers.

Parameters ::=
[ Param [ ',' Param ]* ]

| Param ::= | ... | | [ ParamAttr* ] Type [ marshal '(' [ NativeType ] ')' ] [ Id ]

The Id, if present, is the name of the parameter. A parameter can be referenced either by using its name or the zero-based index of the parameter. In CIL instructions it is always encoded using the zero-based index (the name is for ease of use in ILAsm).

Note that, in contrast to calling a vararg method, the definition of a vararg method does not include any ellipsis ("")

ParamAttr ::=
'[' in ']'
| '[' opt ']'
| '[' out ']'

The parameter attributes shall be attached to the parameters (§II.22.33) and hence are not part of a method signature.

[Note: Unlike parameter attributes, custom modifiers (modopt and modreq) are part of the signature. Thus, modifiers form part of the method's contract while parameter attributes do not. end note]

in and out shall only be attached to parameters of pointer (managed or unmanaged) type. They specify whether the parameter is intended to supply input to the method, return a value from the method, or both. If neither is specified in is assumed. The CLI itself does not enforce the semantics of these bits, although they can be used to optimize performance, especially in scenarios where the call site and the method are in different application domains, processes, or computers.

opt specifies that this parameter is intended to be optional from an end-user point of view. The value to be supplied is stored using the .param syntax (§II.15.4.1.4).