本地函数的属性Attributes on local functions

属性Attributes

本地函数声明现在允许有 属性Local function declarations are now permitted to have attributes. 本地函数上的参数和类型参数也允许有属性。Parameters and type parameters on local functions are also allowed to have attributes.

应用于方法、其参数或其类型参数的属性在应用于本地函数、其参数或其类型参数时具有相同的含义。Attributes with a specified meaning when applied to a method, its parameters, or its type parameters will have the same meaning when applied to a local function, its parameters, or its type parameters, respectively.

局部函数可以通过使用将其与 条件方法 进行修饰来成为条件方法 [ConditionalAttribute]A local function can be made conditional in the same sense as a conditional method by decorating it with a [ConditionalAttribute]. 条件本地函数也必须是 staticA conditional local function must also be static. 条件方法的所有限制也适用于条件本地函数,包括返回类型必须为 voidAll restrictions on conditional methods also apply to conditional local functions, including that the return type must be void.

Extern

extern现在允许对本地函数使用修饰符。The extern modifier is now permitted on local functions. 这使本地函数成为外部 方法的外部函数。This makes the local function external in the same sense as an external method.

与外部方法类似,外部本地函数的 本地函数体 必须是分号。Similarly to an external method, the local-function-body of an external local function must be a semicolon. 只允许对外部本地函数使用分号 局部函数体A semicolon local-function-body is only permitted on an external local function.

外部本地函数也必须是 staticAn external local function must also be static.

语法Syntax

按如下所示修改 本地函数语法The local functions grammar is modified as follows:

local-function-header
    : attributes? local-function-modifiers? return-type identifier type-parameter-list?
        ( formal-parameter-list? ) type-parameter-constraints-clauses
    ;

local-function-modifiers
    : (async | unsafe | static | extern)*
    ;

local-function-body
    : block
    | arrow-expression-body
    | ';'
    ;