You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/classes.md
+46-29Lines changed: 46 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2152,15 +2152,15 @@ A declaration has a valid combination of modifiers if all of the following are t
2152
2152
- If the declaration includes the `private` modifier, then the declaration does not include any of the following modifiers: `virtual`, `override`, or `abstract`.
2153
2153
- If the declaration includes the `sealed` modifier, then the declaration also includes the `override` modifier.
2154
2154
- If the declaration includes the `partial` modifier, then it does not include the modifier `abstract`.
2155
-
- If the declaration is for a restricted partial method ([§15.6.9](classes.md#1569-partial-methods)), then it does not include any of the following modifiers: `new`, `public`, `protected`, `internal`, `private`, `virtual`, `sealed`, `override`, or `extern`.
2155
+
- If the declaration is for a restricted partial method (§restricted-partial-methods), then it does not include any of the following modifiers: `new`, `public`, `protected`, `internal`, `private`, `virtual`, `sealed`, `override`, or `extern`.
2156
2156
2157
2157
Methods are classified according to what, if anything, they return:
2158
2158
2159
2159
- If `ref` is present, the method is ***returns-by-ref*** and returns a *variable reference*, that is optionally read-only;
2160
2160
- Otherwise, if *return_type* is `void`, the method is ***returns-no-value*** and does not return a value;
2161
2161
- Otherwise, the method is ***returns-by-value*** and returns a value.
2162
2162
2163
-
The *return_type* of a returns-by-value or returns-no-value method declaration specifies the type of the result, if any, returned by the method. Only a returns-no-value method may include the `partial` modifier ([§15.6.9](classes.md#1569-partial-methods)). If the declaration includes the `async` modifier then *return_type* for a restricted partial method shall be `void` or the method returns-by-value and the return type is a *task type* ([§15.14.1](classes.md#15141-general)).
2163
+
The *return_type* of a returns-by-value or returns-no-value method declaration specifies the type of the result, if any, returned by the method. If the declaration includes the `async` modifier then *return_type* shall be `void` or the method returns-by-value and the return type is a *task type* ([§15.14.1](classes.md#15141-general)).
2164
2164
2165
2165
The *ref_return_type* of a returns-by-ref method declaration specifies the type of the variable referenced by the *variable_reference* returned by the method.
2166
2166
@@ -2389,7 +2389,7 @@ For a `struct` type, within an instance method, instance accessor ([§12.2.1](ex
2389
2389
2390
2390
A parameter declared with an `out` modifier is an ***output parameter***. For definite-assignment rules, see [§9.2.7](variables.md#927-output-parameters).
2391
2391
2392
-
A method declared as a restricted partial method ([§15.6.9](classes.md#1569-partial-methods)) shall not have output parameters.
2392
+
A method declared as a restricted partial method (§restricted-partial-methods) shall not have output parameters.
-Thedeclarationsshallhavethesamemodifiersexceptfor the `async` and `extern` modifiers. The `async` and `extern` modifiers are allowed only on the implementing partial method declaration.
3037
3045
- Corresponding parameters in the declarations shall have the same modifiers (althoughnotnecessarilyinthesameorder) andthesametypes (modulodifferencesintypeparameternames).
Overtime, thespecificationfor partial methods has evolved, resulting in restricted and unrestricted versions. A ***restricted partial method*** has no explicit access modifiers (andisimplicitlyprivate), hasa `void` returntype, andhasnooutparameters. An***unrestrictedpartialmethod***isapartialmethodthathasexplicitaccessmodifiers, anon-`void` returntype, oranyoutparameters.
>*Note*:Thedefinitionofmatchingdefiningandimplementingpartialmethoddeclarationsdoesnotrequireparameternamestomatch. Thiscanproduce*surprising*, albeit*welldefined*, behaviourwhennamedarguments ([§12.6.2.1](expressions.md#12621-general)) areused. Forexample, giventhedefiningpartialmethoddeclarationfor `M` in one file, and the implementing partial method declaration in another file:
Ifanimplementingdeclarationexistsforagivenpartialmethod, theinvocationsofthepartialmethodsareretained. Thepartialmethodgivesrisetoamethoddeclarationsimilartotheimplementingpartialmethoddeclarationexceptfor the following:
3101
3104
3102
-
- The `partial` modifier is not included.
3103
-
3105
+
- All modifiers except the `partial` modifier are combined, including any `extern` or `async` modifier declared on the implementing declaration.
3104
3106
- The attributes in the resulting method declaration are the combined attributes of the defining and the implementing partial method declaration in unspecified order. Duplicates are not removed.
3105
-
3106
3107
- The attributes on the parameters of the resulting method declaration are the combined attributes of the corresponding parameters of the defining and the implementing partial method declaration in unspecified order. Duplicates are not removed.
3107
-
3108
-
If a defining declaration but not an implementing declaration is given for a restricted partial method `M`, the following restrictions apply:
3109
-
3110
-
- It is a compile-time error to create a delegate from `M` ([§12.8.17.5](expressions.md#128175-delegate-creation-expressions)).
- `M` cannotbetheentrypointfor an application ([§7.1](basic-concepts.md#71-application-startup)).
3108
+
- Any default arguments (§15.6.2) intheimplementingdeclarationareremoved.
3117
3109
3118
3110
Partialmethodsareusefulfor allowing one part of a type declaration to customize the behavior of another part, e.g., one that is generated by a tool. Consider the following partial class declaration:
A restricted partial method shall have a `void` return type, and shall not declare out parameters. There shall be zero or one implementing declaration for each defining declaration. If no part implements the partial method, the partial method declaration and all calls to it are removed from the type declaration resulting from the combination of the parts. Whether or not an implementing declaration is given, invocation expressions may resolve to invocations of the partial method.
3195
+
3196
+
The implementing member for a restricted partial method shall not be an external method (§15.6.8).
3197
+
3198
+
> *Note*: Because a restricted partial method always returns `void`, such invocation expressions will always be expression statements. Furthermore, because a restricted partial method is implicitly `private`, such statements will always occur within one of the parts of the type declaration within which the partial method is declared. *end note*
3199
+
3200
+
If a restricted partial method has no implementation, any expression statement invoking it is removed from the combined type declaration. Thus, the invocation expression, including any subexpressions, has no effect at run-time. The partial method itself is also removed and will not be a member of the combined type declaration.
3201
+
3202
+
If a defining declaration but not an implementing declaration is given for a restricted partial method `M`, the following restrictions apply:
3203
+
3204
+
- It is a compile-time error to create a delegate from `M` ([§12.8.17.5](expressions.md#128175-delegate-creation-expressions)).
3205
+
- It is a compile-time error to refer to `M` inside an anonymous function that is converted to an expression tree type ([§8.6](types.md#86-expression-tree-types)).
3206
+
- Expressions occurring as part of an invocation of `M` do not affect the definite assignment state ([§9.4](variables.md#94-definite-assignment)), which can potentially lead to compile-time errors.
3207
+
-`M` cannot be the entry point for an application ([§7.1](basic-concepts.md#71-application-startup)).
An unrestriced partial method has an explicit access modifier. There shall be exactly one implementing partial method declaration.
3212
+
3213
+
The implementing declaration for an unrestricted partial method may be an external method (§15.6.8).
3214
+
3215
+
> *Note:* The `private` access modifier is required on both the ***defining partial method declaration*** and the ***implementing partial method declaration*** of an unrestricted partial method. *end note*
3216
+
3200
3217
### 15.6.10 Extension methods
3201
3218
3202
3219
When the first parameter of a method includes the `this` modifier, that method is said to be an ***extension method***. Extension methods shall only be declared in non-generic, non-nested static classes. The first parameter of an extension method is restricted, as follows:
@@ -4264,7 +4281,7 @@ The *event_accessor_declarations* of an event specify the executable statements
4264
4281
4265
4282
The accessor declarations consist of an *add_accessor_declaration* and a *remove_accessor_declaration*. Each accessor declaration consists of the token add or remove followed by a *block*. The *block* associated with an *add_accessor_declaration* specifies the statements to execute when an event handler is added, and the *block* associated with a *remove_accessor_declaration* specifies the statements to execute when an event handler is removed.
4266
4283
4267
-
Each *add_accessor_declaration* and *remove_accessor_declaration* corresponds to a method with a single value parameter of the event type, and a `void` return type. The implicit parameter of an event accessor is named `value`. When an event is used in an event assignment, the appropriate event accessor is used. Specifically, if the assignment operator is `+=` then the add accessor is used, and if the assignment operator is `–=` then the remove accessor is used. In either case, the right operand of the assignment operator is used as the argument to the event accessor. The block of an *add_accessor_declaration* or a *remove_accessor_declaration* shall conform to the rules for `void` methods described in [§15.6.9](classes.md#1569-partial-methods). In particular, `return` statements in such a block are not permitted to specify an expression.
4284
+
Each *add_accessor_declaration* and *remove_accessor_declaration* corresponds to a method with a single value parameter of the event type, and a `void` return type. The implicit parameter of an event accessor is named `value`. When an event is used in an event assignment, the appropriate event accessor is used. Specifically, if the assignment operator is `+=` then the add accessor is used, and if the assignment operator is `–=` then the remove accessor is used. In either case, the right operand of the assignment operator is used as the argument to the event accessor. The block of an *add_accessor_declaration* or a *remove_accessor_declaration* shall conform to the rules for `void` methods described in §restricted-partial-methods. In particular, `return` statements in such a block are not permitted to specify an expression.
4268
4285
4269
4286
Since an event accessor implicitly has a parameter named `value`, it is a compile-time error for a local variable or constant declared in an event accessor to have that name.
0 commit comments