Skip to content

Commit b2be879

Browse files
RexJaeschkeBillWagner
authored andcommitted
Add support for module initializers
1 parent 1477dfc commit b2be879

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

standard/attributes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ A number of attributes affect the language in some way. These attributes include
496496
- `System.Runtime.CompilerServices.AsyncMethodBuilderAttribute` ([§23.5.5](attributes.md#2355-the-asyncmethodbuilder-attribute)), which is used to establish a task builder for an async method.
497497
- `System.Runtime.CompilerServices.CallerLineNumberAttribute` ([§23.5.6.2](attributes.md#23562-the-callerlinenumber-attribute)), `System.Runtime.CompilerServices.CallerFilePathAttribute` ([§23.5.6.3](attributes.md#23563-the-callerfilepath-attribute)), and `System.Runtime.CompilerServices.CallerMemberNameAttribute` ([§23.5.6.4](attributes.md#23564-the-callermembername-attribute)), which are used to supply information about the calling context to optional parameters.
498498
- `System.Runtime.CompilerServices.EnumeratorCancellationAttribute` ([§23.5.8](attributes.md#2358-the-enumeratorcancellation-attribute)), which is used to specify parameter for the cancellation token in an asynchronous iterator.
499+
- `System.Runtime.CompilerServices.ModuleInitializer` (§module-init-attr), which is used to mark a method as a module initializer.
499500
500501
The Nullable static analysis attributes ([§23.5.7](attributes.md#2357-code-analysis-attributes)) can improve the correctness of warnings generated for nullabilities and null states ([§8.9.5](types.md#895-nullabilities-and-null-states)).
501502
@@ -1099,6 +1100,22 @@ The iterator won’t have access to the `CancellationToken` argument for `GetAsy
10991100
>
11001101
> *end example*
11011102
1103+
### §module-init-attr The ModuleInitializer attribute
1104+
1105+
The attribute `ModuleInitializer` is used to mark a method as a ***module initializer***. Such a method is called during initialization of the containing module. A module may have multiple initializers, which are called in an implementation-defined order.
1106+
1107+
There are no limitations on what code is permitted in a module initializer.
1108+
1109+
A module initializer shall have the following characteristics:
1110+
1111+
- The *method_modifier* `static`.
1112+
- No *parameter_list*.
1113+
- A *return_type* of `void`.
1114+
- No *type_parameter_list*.
1115+
- Not be declared inside a *class_declaration* having a *type_parameter_list*.
1116+
- Be accessible from the containing module (that is, have an access modifier `internal` or `public`).
1117+
- Not be a local function.
1118+
11021119
## 23.6 Attributes for interoperation
11031120
11041121
For interoperation with other languages, an indexer may be implemented using indexed properties. If no `IndexerName` attribute is present for an indexer, then the name `Item` is used by default. The `IndexerName` attribute enables a developer to override this default and specify a different name.

0 commit comments

Comments
 (0)