Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@
- [§13.12](statements.md#1312-the-checked-and-unchecked-statements) The checked and unchecked statements
- [§13.13](statements.md#1313-the-lock-statement) The lock statement
- [§13.14](statements.md#1314-the-using-statement) The using statement
- [§13.14.1](statements.md#13141-general) General
- [§13.14.2](statements.md#13142-using-declaration) Using declaration
- [§13.15](statements.md#1315-the-yield-statement) The yield statement
- [§14](namespaces.md#14-namespaces) Namespaces
- [§14.1](namespaces.md#141-general) General
Expand Down Expand Up @@ -771,6 +773,7 @@
- [§23.5.7.8](attributes.md#23578-the-notnull-attribute) The NotNull attribute
- [§23.5.7.9](attributes.md#23579-the-notnullifnotnull-attribute) The NotNullIfNotNull attribute
- [§23.5.7.10](attributes.md#235710-the-notnullwhen-attribute) The NotNullWhen attribute
- [§23.5.8](attributes.md#2358-the-enumeratorcancellation-attribute) The EnumeratorCancellation attribute
- [§23.6](attributes.md#236-attributes-for-interoperation) Attributes for interoperation
- [§24](unsafe-code.md#24-unsafe-code) Unsafe code
- [§24.1](unsafe-code.md#241-general) General
Expand Down
10 changes: 5 additions & 5 deletions standard/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
- `System.ObsoleteAttribute` ([§23.5.4](attributes.md#2354-the-obsolete-attribute)), which is used to mark a member as obsolete.
- `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.
- `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.
- `System.Runtime.CompilerServices.EnumeratorCancellationAttribute` (§enumerator-cancellation), which is used to specify parameter for the cancellation token in an asynchronous iterator.
- `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.

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)).

Expand Down Expand Up @@ -953,11 +953,11 @@
> ```csharp
> #nullable enable
> public class X
> {

Check warning on line 956 in standard/attributes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/attributes.md#L956

MDC032::Line length 86 > maximum 81
> private void ThrowIfNull([DoesNotReturnIf(true)] bool isNull, string argumentName)
> {
> if (!isNull)
> {

Check warning on line 960 in standard/attributes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/attributes.md#L960

MDC032::Line length 96 > maximum 81
> throw new ArgumentException(argumentName, $"argument {argumentName} can't be null");
> }
> }
Expand Down Expand Up @@ -1011,7 +1011,7 @@
>
> <!-- Example: {template:"code-in-class-lib", name:"NotNullAttribute"} -->
> ```csharp
> #nullable enable

Check warning on line 1014 in standard/attributes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/attributes.md#L1014

MDC032::Line length 89 > maximum 81
> public static void ThrowWhenNull([NotNull] object? value, string valueExpression = "") =>
> _ = value ?? throw new ArgumentNullException(valueExpression);
>
Expand Down Expand Up @@ -1061,17 +1061,17 @@
>
> *end example*

### §enumerator-cancellation The EnumeratorCancellation attribute
### 23.5.8 The EnumeratorCancellation attribute

Specifies the parameter representing the `CancellationToken` for an asynchronous iterator (§15.15). The argument for this parameter shall be combined with the argument passed to `IAsyncEnumerable<T>.GetAsyncEnumerator(CancellationToken)`. This combined token shall be polled by `IAsyncEnumerator<T>.MoveNextAsync()` (§15.15.5.2). The tokens shall be combined into a single token as if by `CancellationToken.CreateLinkedTokenSource` and its `Token` property. The combined token will be canceled if either of the two source tokens are canceled. The combined token is seen as the argument to the asynchronous iterator method (§15.15) in the body of that method.
Specifies the parameter representing the `CancellationToken` for an asynchronous iterator ([§15.15](classes.md#1515-synchronous-and-asynchronous-iterators)). The argument for this parameter shall be combined with the argument passed to `IAsyncEnumerable<T>.GetAsyncEnumerator(CancellationToken)`. This combined token shall be polled by `IAsyncEnumerator<T>.MoveNextAsync()` ([§15.15.5.2](classes.md#151552-advance-the-enumerator)). The tokens shall be combined into a single token as if by `CancellationToken.CreateLinkedTokenSource` and its `Token` property. The combined token will be canceled if either of the two source tokens are canceled. The combined token is seen as the argument to the asynchronous iterator method ([§15.15](classes.md#1515-synchronous-and-asynchronous-iterators)) in the body of that method.

It is an error if the `System.Runtime.CompilerServices.EnumeratorCancellation` attribute is applied to more than one parameter. The compiler may produce a warning if:

- The `EnumeratorCancellation` attribute is applied to a parameter of a type other than `CancellationToken`,
- or if the `EnumeratorCancellation` attribute is applied to a parameter on a method that isn't an asynchronous iterator (§15.15),
- or if the `EnumeratorCancellation` attribute is applied to a parameter on a method that isnt an asynchronous iterator ([§15.15](classes.md#1515-synchronous-and-asynchronous-iterators)),
- or if the `EnumeratorCancellation` attribute is applied to a parameter on a method that returns an asynchronous enumerable interface ([§15.15.3](classes.md#15153-enumerable-interfaces)) rather than an asynchronous enumerator interface ([§15.15.2](classes.md#15152-enumerator-interfaces)).

The iterator won't have access to the `CancellationToken` argument for `GetAsyncEnumerator` when no attributes have this parameter.
The iterator wont have access to the `CancellationToken` argument for `GetAsyncEnumerator` when no attributes have this parameter.

> *Example*: The method `GetStringsAsync()` is an asynchronous iterator. Before doing any work to retrieve the next value, it checks the cancellation token to determine if the iteration should be canceled. If cancellation is requested, no further action is taken.
>
Expand All @@ -1093,7 +1093,7 @@
> }
> }
> }
>

Check warning on line 1096 in standard/attributes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/attributes.md#L1096

MDC032::Line length 103 > maximum 81
> static async IAsyncEnumerable<string> GetStringsAsync([EnumeratorCancellation] CancellationToken token)
> {
> for (int i = 0; i < 10; i++)
Expand Down
8 changes: 4 additions & 4 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
: 'where' type_parameter ':' type_parameter_constraints
;

type_parameter_constraints

Check warning on line 398 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L398

MDC032::Line length 83 > maximum 81
: primary_constraint (',' secondary_constraints)? (',' constructor_constraint)?
| secondary_constraints (',' constructor_constraint)?
| constructor_constraint
Expand Down Expand Up @@ -503,15 +503,15 @@
> static void M()
> {
> // nonnull constraint allows nonnullable struct type argument
> A<int> x1;

Check warning on line 506 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L506

MDC032::Line length 87 > maximum 81
> // possible warning: nonnull constraint prohibits nullable struct type argument
> A<int?> x2;
> // nonnull constraint allows nonnullable class type argument
> A<C> x3;

Check warning on line 510 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L510

MDC032::Line length 86 > maximum 81
> // possible warning: nonnull constraint prohibits nullable class type argument
> A<C?> x4;

Check warning on line 512 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L512

MDC032::Line length 84 > maximum 81
> // nonnullable base class requirement allows nonnullable class type argument
> B1<C> x5;

Check warning on line 514 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L514

MDC032::Line length 102 > maximum 81
> // possible warning: nonnullable base class requirement prohibits nullable class type argument
> B1<C?> x6;
> // nullable base class requirement allows nonnullable class type argument
Expand Down Expand Up @@ -3457,7 +3457,7 @@
> static void Main()
> {
> field = 10;
> Console.WriteLine(Property); // Prints 10

Check warning on line 3460 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L3460

MDC032::Line length 83 > maximum 81
> Property = 20; // This invokes the get accessor, then assigns
> // via the resulting variable reference
> Console.WriteLine(field); // Prints 20
Expand Down Expand Up @@ -4572,7 +4572,7 @@
: '!'
;

overloadable_unary_operator

Check warning on line 4575 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L4575

MDC032::Line length 82 > maximum 81
: '+' | '-' | logical_negation_operator | '~' | '++' | '--' | 'true' | 'false'
;

Expand Down Expand Up @@ -5504,7 +5504,7 @@

When a function is implemented using an iterator block, it is a compile-time error for the parameter list of the function to specify any `in`, `out`, or `ref` parameters, or a parameter of a `ref struct` type.

An asynchronous iterator shall support cancellation of the asynchronous operation. This is described in §enumerator-cancellation.
An asynchronous iterator shall support cancellation of the asynchronous operation. This is described in [§23.5.8](attributes.md#2358-the-enumeratorcancellation-attribute).

### 15.15.2 Enumerator interfaces

Expand Down Expand Up @@ -5575,7 +5575,7 @@

When `MoveNext` executes the iterator block, execution can be interrupted in four ways: By a `yield return` statement, by a `yield break` statement, by encountering the end of the iterator block, and by an exception being thrown and propagated out of the iterator block.

> *Note*: `MoveNextAsync` is suspended if it evaluates an `await` expression that awaits a task type that hasn't completed. *end note*
> *Note*: `MoveNextAsync` is suspended if it evaluates an `await` expression that awaits a task type that hasnt completed. *end note*

- When a `yield return` statement is encountered ([§9.4.4.20](variables.md#94420-yield-statements)):
- The expression given in the statement is evaluated, implicitly converted to the yield type, and assigned to the `Current` property of the enumerator object.
Expand Down Expand Up @@ -5622,7 +5622,7 @@

When a function member or local function returning an enumerable interface type or an async enumerable interface type is implemented using an iterator block, invoking the function does not immediately execute the code in the iterator block. Instead, an ***enumerable object*** is created and returned.

A synchronous enumerable object implements `IEnumerable` and `IEnumerable<T>`, where `T` is the yield type of the iterator. Its `GetEnumerator` method returns an enumerator object (§15.15.5). An async enumerable object implements `IAsyncEnumerable<T>` where `T` is the yield type of the iterator. Its `GetAsyncEnumerator` method returns an asynchronous enumerator object (§15.15.5).
A synchronous enumerable object implements `IEnumerable` and `IEnumerable<T>`, where `T` is the yield type of the iterator. Its `GetEnumerator` method returns an enumerator object ([§15.15.5](classes.md#15155-enumerator-objects)). An async enumerable object implements `IAsyncEnumerable<T>` where `T` is the yield type of the iterator. Its `GetAsyncEnumerator` method returns an asynchronous enumerator object ([§15.15.5](classes.md#15155-enumerator-objects)).

An enumerable object is initialized with a copy of the argument values (if any) and instance value passed to the function.

Expand All @@ -5636,4 +5636,4 @@

An enumerable object provides an implementation of the `GetEnumerator` methods of the `IEnumerable` and `IEnumerable<T>` interfaces. The two `GetEnumerator` methods share a common implementation that acquires and returns an available enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects).

An asynchronous enumerable object provides an implementation of the `GetAsyncEnumerator` method of the `IAsyncEnumerable<T>` interface. This method returns an available asynchronous enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, including the optional cancellation token, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects). An asynchronous iterator method can mark one parameter as the cancellation token using `System.Runtime.CompilerServices.EnumeratorCancellationAttribute` (§enumerator-cancellation). An implementation shall provide a mechanism to combine cancellation tokens such that an asynchronous iterator is canceled when either cancellation token (the argument to `GetAsyncEnumerator` or the argument attributed with the attribute `System.Runtime.CompilerServices.EnumeratorCancellationAttribute`) requests cancellation.
An asynchronous enumerable object provides an implementation of the `GetAsyncEnumerator` method of the `IAsyncEnumerable<T>` interface. This method returns an available asynchronous enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, including the optional cancellation token, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects). An asynchronous iterator method can mark one parameter as the cancellation token using `System.Runtime.CompilerServices.EnumeratorCancellationAttribute` ([§23.5.8](attributes.md#2358-the-enumeratorcancellation-attribute)). An implementation shall provide a mechanism to combine cancellation tokens such that an asynchronous iterator is canceled when either cancellation token (the argument to `GetAsyncEnumerator` or the argument attributed with the attribute `System.Runtime.CompilerServices.EnumeratorCancellationAttribute`) requests cancellation.
16 changes: 13 additions & 3 deletions standard/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,8 @@
: primary_expression '(' argument_list? ')'
;

// Source: §12.8.11 Null Conditional Invocation Expression

Check warning on line 998 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L998

MDC032::Line length 84 > maximum 81
null_conditional_invocation_expression

Check warning on line 999 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L999

MDC032::Line length 85 > maximum 81
: null_conditional_member_access null_forgiving_operator? '(' argument_list? ')'
| null_conditional_element_access null_forgiving_operator? '(' argument_list? ')'
;
Expand Down Expand Up @@ -1127,8 +1127,8 @@
| 'typeof' '(' unbound_type_name ')'
| 'typeof' '(' 'void' ')'
;

Check warning on line 1130 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L1130

MDC032::Line length 92 > maximum 81
unbound_type_name

Check warning on line 1131 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L1131

MDC032::Line length 83 > maximum 81
: identifier generic_dimension_specifier? ('.' identifier generic_dimension_specifier?)*
| unbound_qualified_alias_member ('.' identifier generic_dimension_specifier?)*
;
Expand Down Expand Up @@ -1175,7 +1175,7 @@
;

// Source: §12.8.22 Stack allocation
stackalloc_expression

Check warning on line 1178 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L1178

MDC032::Line length 86 > maximum 81
: 'stackalloc' unmanaged_type '[' expression ']'
| 'stackalloc' unmanaged_type? '[' constant_expression? ']' stackalloc_initializer
;
Expand Down Expand Up @@ -1478,7 +1478,7 @@
assignment
: unary_expression assignment_operator expression
;

Check warning on line 1481 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L1481

MDC032::Line length 88 > maximum 81
assignment_operator
: '=' 'ref'? | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '??='
| right_shift_assignment
Expand Down Expand Up @@ -1838,16 +1838,26 @@
: 'lock' '(' expression ')' embedded_statement
;

// Source: §13.14 The using statement
// Source: §13.14.1 General
using_statement
: 'using' '(' resource_acquisition ')' embedded_statement
: 'await'? 'using' '(' resource_acquisition ')' embedded_statement
;

resource_acquisition
: local_variable_declaration
: non_ref_local_variable_declaration
| expression
;

non_ref_local_variable_declaration
: implicitly_typed_local_variable_declaration
| explicitly_typed_local_variable_declaration
;

// Source: §13.14.2 Using declaration
using_declaration
: 'await'? 'using' non_ref_local_variable_declaration ';' statement_list?
;

// Source: §13.15 The yield statement
yield_statement
: 'yield' 'return' expression ';'
Expand Down Expand Up @@ -1965,7 +1975,7 @@
type_parameter_constraints_clause
: 'where' type_parameter ':' type_parameter_constraints
;

Check warning on line 1978 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L1978

MDC032::Line length 83 > maximum 81
type_parameter_constraints
: primary_constraint (',' secondary_constraints)? (',' constructor_constraint)?
| secondary_constraints (',' constructor_constraint)?
Expand Down Expand Up @@ -2334,7 +2344,7 @@
logical_negation_operator
: '!'
;

Check warning on line 2347 in standard/grammar.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/grammar.md#L2347

MDC032::Line length 82 > maximum 81
overloadable_unary_operator
: '+' | '-' | logical_negation_operator | '~' | '++' | '--' | 'true' | 'false'
;
Expand Down
Loading
Loading