Skip to content
Draft
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
72 changes: 72 additions & 0 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
: 'where' type_parameter ':' type_parameter_constraints
;

type_parameter_constraints

Check warning on line 425 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L425

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

Check warning on line 537 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L537

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 541 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L541

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

Check warning on line 543 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L543

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

Check warning on line 545 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L545

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

Check warning on line 3559 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L3559

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 @@ -4917,7 +4917,7 @@
: '!'
;

overloadable_unary_operator

Check warning on line 4920 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L4920

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

Expand Down Expand Up @@ -5886,6 +5886,78 @@

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

Rather than using a task builder type based on the *return_type* of an async method, the attribute `AsyncMethodBuilder` can be applied to that method to indicate a different task builder type.

It is an error to apply this attribute to a lambda with an implicit return type.

The ability to provide an alternate builder type shall not be used when the synthesized entry-point for top-level statements is async ([§7.1.3](basic-concepts.md#713-using-top-level-statements)). For that, an explicit entry-point is needed.

When an async method is compiled, the builder type is determined by:

1. Using the builder type from the `AsyncMethodBuilder` attribute, if one is present;
1. Otherwise, falling back to the builder type determined by the method’s *return_type*.

If an `AsyncMethodBuilder` attribute is present, the builder type specified by that attribute is constructed, if necessary.

If the override type is an open generic type, take the single type argument of the async method's return type and substitute it into the override type.

If the override type is a bound generic type, then an error results.

If the async method's return type does not have a single type argument, an error results.

To verify that the builder type is compatible with *return_type* of the async method:

1. Look for the public `Create` method with no type parameters and no parameters on the constructed builder type. It is an error if the method is not found, or if the method returns a type other than the constructed builder type.
1. Look for the public `Task` property. It is an error if the property is not found.
1. Consider the type of that `Task` property (a task-like type). It is an error if the task-like type does not match the *return_type* of the async method. (It is not necessary for *return_type* to be a task-like type.)

Consider the following code fragment:

```csharp
public async ValueTask<T> ExampleAsync() { … }
```

This will be compiled to something like the following:

```csharp
[AsyncStateMachine(typeof(<ExampleAsync>d__29))]
[CompilerGenerated]
static ValueTask<int> ExampleAsync()
{
<ExampleAsync>d__29 stateMachine;
stateMachine.<>t__builder
= AsyncValueTaskMethodBuilder<int>.Create();
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
```

However, the following code fragment:

```csharp
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
static async ValueTask<int> ExampleAsync() { … }
```

in which the attribute `AsyncMethodBuilder` is applied to that method, would instead be compiled to something like:

```csharp
[AsyncStateMachine(typeof(<ExampleAsync>d__29))]
[CompilerGenerated]
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
static ValueTask<int> ExampleAsync()
{
<ExampleAsync>d__29 stateMachine;
stateMachine.<>t__builder
= PoolingAsyncValueTaskMethodBuilder<int>.Create();
// <>t__builder now a different type
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
```

### 15.15.2 Enumerator interfaces

The ***enumerator interface***s are the non-generic interface `System.Collections.IEnumerator` and the generic interface `System.Collections.Generic.IEnumerator<T>`.
Expand Down Expand Up @@ -6134,7 +6206,7 @@
> public static bool operator!=(R1? left, R1? right) => !(left == right);
>
> public override int GetHashCode()
> {

Check warning on line 6209 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L6209

MDC032::Line length 93 > maximum 81
> return HashCode.Combine(EqualityComparer<Type>.Default.GetHashCode(EqualityContract),
> EqualityComparer<T1>.Default.GetHashCode(P1));
> }
Expand Down Expand Up @@ -6315,7 +6387,7 @@
> protected virtual bool PrintMembers(StringBuilder builder)
> {
> builder.Append(nameof(P1));
> builder.Append(" = ");

Check warning on line 6390 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L6390

MDC032::Line length 97 > maximum 81
> builder.Append(this.P1); // or builder.Append(this.P1.ToString()); if P1 has a value type
> return true;
> }
Expand Down Expand Up @@ -6346,11 +6418,11 @@
> builder.Append(", ");
> }
> builder.Append(nameof(P2));
> builder.Append(" = ");

Check warning on line 6421 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L6421

MDC032::Line length 86 > maximum 81
> builder.Append(this.P2); // or builder.Append(this.P2); if P2 has a value type
> builder.Append(", ");
> builder.Append(nameof(P3));
> builder.Append(" = ");

Check warning on line 6425 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L6425

MDC032::Line length 86 > maximum 81
> builder.Append(this.P3); // or builder.Append(this.P3); if P3 has a value type
> return true;
> }
Expand Down Expand Up @@ -6484,5 +6556,5 @@
>
> *end example*


Check failure on line 6559 in standard/classes.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

standard/classes.md:6559 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md

Check failure on line 6560 in standard/classes.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

standard/classes.md:6560 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 3] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md
2 changes: 1 addition & 1 deletion standard/standard-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
public class NullReferenceException : Exception
{
public NullReferenceException();
public NullReferenceException(string? message);

Check warning on line 193 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L193

MDC032::Line length 82 > maximum 81
public NullReferenceException(string? message, Exception? innerException);
}

Expand Down Expand Up @@ -238,7 +238,7 @@
public sealed class StackOverflowException : Exception
{
public StackOverflowException();
public StackOverflowException(string? message);

Check warning on line 241 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L241

MDC032::Line length 82 > maximum 81
public StackOverflowException(string? message, Exception? innerException);
}

Expand All @@ -247,7 +247,7 @@
public int Length { get; }
public char this [int index] { get; }
public static string Format(string format, params object?[] args);
System.Collections.IEnumerator IEnumerable.GetEnumerator();

Check warning on line 250 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L250

MDC032::Line length 87 > maximum 81
System.Collections.Generic.IEnumerator<char> IEnumerable<char>.GetEnumerator();
}

Expand Down Expand Up @@ -407,7 +407,7 @@
public class OperationCanceledException : Exception
{
public OperationCanceledException();
public OperationCanceledException(string? message);

Check warning on line 410 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L410

MDC032::Line length 86 > maximum 81
public OperationCanceledException(string? message, Exception? innerException);
}

Expand Down Expand Up @@ -680,7 +680,7 @@
}

public interface IAsyncEnumerable<out T>
{

Check warning on line 683 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L683

MDC032::Line length 82 > maximum 81
IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken token = default);
}

Expand Down Expand Up @@ -747,7 +747,7 @@
System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
public sealed class MemberNotNullWhenAttribute : Attribute
{
public MemberNotNullWhenAttribute(bool returnValue, string member) {}

Check warning on line 750 in standard/standard-library.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/standard-library.md#L750

MDC032::Line length 87 > maximum 81
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) {}
}

Expand Down Expand Up @@ -785,7 +785,7 @@
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Interface,
AttributeTargets.Interface | AttributeTargets.Method,
Inherited = false, AllowMultiple = false)]
public sealed class AsyncMethodBuilderAttribute : Attribute
{
Expand Down
Loading