Skip to content

Commit 1505747

Browse files
RexJaeschkeBillWagner
authored andcommitted
Add support for module initializers
Add support for module initializers Add support for module initializers fix md formatting
1 parent d68b04d commit 1505747

3 files changed

Lines changed: 24 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
@@ -1148,6 +1149,22 @@ The iterator will not have access to the `CancellationToken` argument for `GetAs
11481149
>
11491150
> *end example*
11501151
1152+
### §module-init-attr The ModuleInitializer attribute
1153+
1154+
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.
1155+
1156+
There are no limitations on what code is permitted in a module initializer.
1157+
1158+
A module initializer shall have the following characteristics:
1159+
1160+
- The *method_modifier* `static`.
1161+
- No *parameter_list*.
1162+
- A *return_type* of `void`.
1163+
- No *type_parameter_list*.
1164+
- Not be declared inside a *class_declaration* having a *type_parameter_list*.
1165+
- Be accessible from the containing module (that is, have an access modifier `internal` or `public`).
1166+
- Not be a local function.
1167+
11511168
## 23.6 Attributes for interoperation
11521169
11531170
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.

standard/portability-issues.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ A conforming implementation is required to document its choice of behavior in ea
4343
1. The impact of thread termination when a thread has no handler for an exception, and the thread is itself terminated. ([§13.10.6](statements.md#13106-the-throw-statement))
4444
1. The mechanism by which linkage to an external method is achieved. ([§15.6.8](classes.md#1568-external-methods))
4545
1. The impact of thread termination when no matching `catch` clause is found for an exception and the code that initially started that thread is reached. ([§22.4](exceptions.md#224-how-exceptions-are-handled)).
46+
1. The order of execution of module initializers in a module (§module-init-attr).
4647
1. An execution environment may provide additional attributes that affect the execution of a C# program. ([§23.5.1](attributes.md#2351-general))
4748
1. The mappings between pointers and integers. ([§24.5.1](unsafe-code.md#2451-general))
4849
1. The effect of applying the unary `*` operator to a `null` pointer. ([§24.6.2](unsafe-code.md#2462-pointer-indirection))

standard/standard-library.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ namespace System.Runtime.CompilerServices
829829
void OnCompleted(Action continuation);
830830
}
831831

832+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
833+
public sealed class ModuleInitializerAttribute : Attribute
834+
{
835+
public ModuleInitializerAttribute() { }
836+
}
837+
832838
public readonly struct TaskAwaiter : ICriticalNotifyCompletion,
833839
INotifyCompletion
834840
{

0 commit comments

Comments
 (0)