Attributes on local functions
This article is a feature specification. The specification represents the proposed feature specification. There may be some discrepancies between the feature specification and the completed implementation. Those differences are captured in the pertinent language design meeting (LDM) notes. Links to pertinent meetings are included at the bottom of the spec. You can learn more about the process for merging feature speclets into the C# language standard in the article on the specifications.
Local function declarations are now permitted to have attributes (§21). 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.
A local function can be made conditional in the same sense as a conditional method (§21.5.3) by decorating it with a
[ConditionalAttribute]. A conditional local function must also be
static. All restrictions on conditional methods also apply to conditional local functions, including that the return type must be
extern modifier is now permitted on local functions. This makes the local function external in the same sense as an external method (§14.6.8).
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.
An external local function must also be
The local functions grammar is modified as follows:
: attributes? local-function-modifiers? return-type identifier type-parameter-list?
( formal-parameter-list? ) type-parameter-constraints-clauses
: (async | unsafe | static | extern)*