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
6 changes: 3 additions & 3 deletions standard/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ Certain contexts permit the specification of an attribute on more than one targe
- For an attribute specified on an event declaration that omits *event_accessor_declarations* the default target is the event declaration. Otherwise when the *attribute_target* is equal to:
- `event` — the target is the event declaration
- `field` — the target is the field
- `method` — the targets are the methods
- `method` — the targets are the methods (however, `method` is ignored on a partial event declaration)
- In the case of an event declaration that does not omit *event_accessor_declarations* the default target is the method.
- `method` — the target is the associated method
- `method` — the target is the associated method (however, `method` is ignored on a partial event declaration)
- `param` — the target is the lone parameter
- For an attribute on a *lambda_expression* the default target is the method. Otherwise when the *attribute_target* is equal to:
- `method` — the target is the method
Expand Down Expand Up @@ -807,7 +807,7 @@ When an optional parameter is annotated with one of the caller-info attributes,

Caller-info attributes can occur on optional parameters anywhere, including in delegate declarations. However, the specific caller-info attributes have restrictions on the types of the parameters they can attribute, so that there will always be an implicit conversion from a substituted value to the parameter type.

It is an error to have the same caller-info attribute on a parameter of both the defining and implementing part of a partial method or partial indexer declaration. Only caller-info attributes in the defining part are applied, whereas caller-info attributes occurring only in the implementing part are ignored.
It is an error to have the same caller-info attribute on a parameter of both the defining and implementing part of a partial method, partial indexer, partial event, or partial constructor declaration. Only caller-info attributes in the defining part are applied, whereas caller-info attributes occurring only in the implementing part are ignored.

Caller information does not affect overload resolution. As the attributed optional parameters are still omitted from the source code of the caller, overload resolution ignores those parameters in the same way it ignores other omitted optional parameters ([§12.6.4](expressions.md#1264-overload-resolution)).

Expand Down
68 changes: 64 additions & 4 deletions standard/classes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 15 Classes

Check warning on line 2 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L2

MDC032::Line length 83 > maximum 81

Check warning on line 2 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L2

MDC032::Line length 82 > maximum 81

Check warning on line 2 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L2

MDC032::Line length 90 > maximum 81
## 15.1 General

Check warning on line 3 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L3

MDC032::Line length 88 > maximum 81

Check warning on line 3 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L3

MDC032::Line length 91 > maximum 81

Check warning on line 3 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L3

MDC032::Line length 91 > maximum 81

A class is a data structure that may contain data members (constants and fields), function members (methods, properties, events, indexers, operators, instance constructors, finalizers, and static constructors), and nested types. Class types support inheritance, a mechanism whereby a ***derived class*** can extend and specialize a ***base class***.
Expand All @@ -7,18 +7,18 @@
Structs ([§16](structs.md#16-structs)) and interfaces ([§19](interfaces.md#19-interfaces)) have members similar to classes but with certain restrictions. This clause defines the declarations for classes and class members. The clauses for structs and interfaces define the restrictions for those types in terms of the corresponding declarations in class types.

## 15.2 Class declarations

Check warning on line 10 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L10

MDC032::Line length 83 > maximum 81
### 15.2.1 General

Check warning on line 11 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L11

MDC032::Line length 83 > maximum 81

Check warning on line 12 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L12

MDC032::Line length 87 > maximum 81
A *class_declaration* is a *type_declaration* ([§14.8](namespaces.md#148-type-declarations)) that declares a new class.

```ANTLR
class_declaration

Check warning on line 16 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L16

MDC032::Line length 86 > maximum 81
: non_record_class_declaration
| record_class_declaration

Check warning on line 18 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L18

MDC032::Line length 84 > maximum 81
;

Check warning on line 20 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L20

MDC032::Line length 82 > maximum 81
non_record_class_declaration

Check warning on line 21 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L21

MDC032::Line length 93 > maximum 81
: non_record_class_without_positional_members
| non_record_class_with_positional_members
;
Expand All @@ -27,7 +27,7 @@
: attributes? class_modifier* 'partial'? 'class' identifier
type_parameter_list? class_base?
type_parameter_constraints_clause* class_body
;

Check warning on line 30 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L30

MDC032::Line length 115 > maximum 81

non_record_class_with_positional_members
: attributes? class_modifier* 'partial'? 'class' identifier
Expand All @@ -36,8 +36,8 @@
;
```

There are two kinds of class: ***non-record class***, as declared by *non_record_class_declaration*, and ***record class***, as declared by *record_class_declaration*. A non-record class is the kind of class that C# has supported since the language’s inception. Record classes were added much later and are discussed in [§15.16](classes.md#1516-record-classes). The differences between the two kinds are discussed in [§15.18](classes.md#1518-record-class-and-non-record-class-differences).

Check warning on line 39 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L39

MDC032::Line length 108 > maximum 81

Check warning on line 40 in standard/classes.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/classes.md#L40

MDC032::Line length 82 > maximum 81
A *non_record_class_declaration* can have one of two almost identical forms: *non_record_class_without_positional_members* and *non_record_class_with_positional_members*.

A *non_record_class_without_positional_members* consists of an optional set of *attributes* ([§23](attributes.md#23-attributes)), followed by an optional set of *class_modifier*s ([§15.2.2](classes.md#1522-class-modifiers)), followed by an optional `partial` modifier ([§15.2.7](classes.md#1527-partial-type-declarations)), followed by the keyword `class` and an *identifier* that names the class, followed by an optional *type_parameter_list* ([§15.2.3](classes.md#1523-type-parameters)), followed by an optional *class_base* specification ([§15.2.4](classes.md#1524-class-base-specification)), followed by an optional set of *type_parameter_constraints_clause*s ([§15.2.5](classes.md#1525-type-parameter-constraints)), followed by a *class_body* ([§15.2.6](classes.md#1526-class-body)).
Expand Down Expand Up @@ -861,7 +861,7 @@

### 15.2.7 Partial type declarations

The modifier `partial` is used when defining a class, struct, or interface type in multiple parts. The `partial` modifier is a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) and has special meaning in a *class_declaration*, a *struct_declaration*, or an *interface_declaration*. (A partial type may contain partial method declarations ([§15.6.9](classes.md#1569-partial-methods)), partial property declarations ([§15.7.7](classes.md#1577-partial-properties)), and partial indexer declarations ([§15.9.3](classes.md#1593-partial-indexers))).
The modifier `partial` is used when defining a class, struct, or interface type in multiple parts. The `partial` modifier is a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) and has special meaning in a *class_declaration*, a *struct_declaration*, or an *interface_declaration*. (A partial type may contain partial method declarations ([§15.6.9](classes.md#1569-partial-methods)), partial property declarations ([§15.7.7](classes.md#1577-partial-properties)), partial indexer declarations ([§15.9.3](classes.md#1593-partial-indexers))), partial event declarations (§partial-events), and partial instance constructor declarations (§partial-constructors)).

Each part of a ***partial type*** declaration shall include a `partial` modifier and shall be declared in the same namespace or containing type as the other parts. The `partial` modifier indicates that additional parts of the type declaration might exist elsewhere, but the existence of such additional parts is not a requirement; it is valid for the only declaration of a type to include the `partial` modifier. It is valid for only one declaration of a partial type to include the base class or implemented interfaces. However, all declarations of a base class or implemented interfaces shall match, including the nullability of any specified type arguments.

Expand Down Expand Up @@ -4672,8 +4672,8 @@

```ANTLR
event_declaration
: attributes? event_modifier* 'event' type variable_declarators ';'
| attributes? event_modifier* 'event' type member_name
: attributes? event_modifier* 'partial'? 'event' type variable_declarators ';'
| attributes? event_modifier* 'partial'? 'event' type member_name
'{' event_accessor_declarations '}'
;

Expand Down Expand Up @@ -4707,6 +4707,8 @@
;
```

However, a partial event (§partial-events) shall not have an `abstract` modifier.

*unsafe_modifier* ([§24.2](unsafe-code.md#242-unsafe-contexts)) is only available in unsafe code ([§24](unsafe-code.md#24-unsafe-code)).

An *event_declaration* may include a set of *attributes* ([§23](attributes.md#23-attributes)) and any one of the permitted kinds of declared accessibility ([§15.3.6](classes.md#1536-access-modifiers)), the `new` ([§15.3.5](classes.md#1535-the-new-modifier)), `static` ([§15.6.3](classes.md#1563-static-and-instance-methods), [§15.8.4](classes.md#1584-static-and-instance-events)), `virtual` ([§15.6.4](classes.md#1564-virtual-methods), [§15.8.5](classes.md#1585-virtual-sealed-override-and-abstract-accessors)), `override` ([§15.6.5](classes.md#1565-override-methods), [§15.8.5](classes.md#1585-virtual-sealed-override-and-abstract-accessors)), `sealed` ([§15.6.6](classes.md#1566-sealed-methods)), `abstract` ([§15.6.7](classes.md#1567-abstract-methods), [§15.8.5](classes.md#1585-virtual-sealed-override-and-abstract-accessors)) and `extern` ([§15.6.8](classes.md#1568-external-methods)) modifiers. Additionally an *event_declaration* that is contained directly by a *struct_declaration* may include the `readonly` modifier ([§16.8.12](structs.md#16812-methods)).
Expand Down Expand Up @@ -4947,6 +4949,34 @@

Except for differences in declaration and invocation syntax, virtual, sealed, override, and abstract accessors behave exactly like virtual, sealed, override and abstract methods. Specifically, the rules described in [§15.6.4](classes.md#1564-virtual-methods), [§15.6.5](classes.md#1565-override-methods), [§15.6.6](classes.md#1566-sealed-methods), and [§15.6.7](classes.md#1567-abstract-methods) apply as if accessors were methods of a corresponding form. Each accessor corresponds to a method with a single value parameter of the event type, a `void` return type, and the same modifiers as the containing event.

### §partial-events Partial events

When an *event_declaration* includes `partial`, that event is said to be a ***partial event***. Partial events may only be declared as members of partial types ([§15.2.7](classes.md#1527-partial-type-declarations)).

Partial events may be defined in one part of a type declaration and implemented in another, or be defined and implemented in the same part.

There are two kinds of partial event declarations: If the *event_accessor_declarations* are omitted and the event has no `extern` modifier, the declaration is said to be a ***defining partial event declaration***. Otherwise, the declaration is said to be an ***implementing partial event declaration***.

Partial events are useful for allowing one part of a type declaration to customize the behavior of another part, e.g., one that is generated by a tool.

Across the parts of a type declaration, there shall be only one defining partial event declaration with a given signature, and there shall be only one implementing partial event declaration with a given signature.

The signature-matching requirements are as follows:

1. Type and ref-kind differences between partial event declarations result in a compile-time error.
1. Differences in tuple element names within partial event declarations result in a compile-time error.
1. The event declarations shall have the same modifiers, though the modifiers may appear in a different order. However, this does not apply to the `extern` modifier, which may only appear on an implementing partial declaration.
1. All other syntactic differences in the signatures of partial event declarations result in a compile-time warning, with the following exceptions:
- Attribute lists do not need to match.
- Nullable context differences (such as oblivious vs. annotated) do not cause warnings.
1. Nullability differences which do not involve oblivious nullability result in warnings.

In *event_declaration*, the identifier `partial` is recognized as a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) only if it immediately precedes the event’s type. A partial event cannot explicitly implement interface events.

Only a defining partial event participates in lookup.

A partial event is not field-like ([§15.8.2]( classes.md#1582-field-like-events)).

## 15.9 Indexers

### 15.9.1 General
Expand Down Expand Up @@ -5540,7 +5570,7 @@

```ANTLR
constructor_declaration
: attributes? constructor_modifier* constructor_declarator constructor_body
: attributes? constructor_modifier* 'partial'? constructor_declarator constructor_body
;

constructor_modifier
Expand Down Expand Up @@ -5924,6 +5954,36 @@
- For a ref parameter, if the parameter is not read or written to within any instance initializers or base initializer.
A *class_declaration* may have a `method:` attribute target, which shall apply to the corresponding primary constructor, if any. If the class has no *delimited_parameter_list*, this attribute shall be ignored and a warning produced.

### §partial-constructors Partial constructors

When a *constructor_declaration* includes a `partial` modifier, that constructor is said to be a ***partial constructor***. Partial constructors may only be declared as members of partial types ([§15.2.7](classes.md#1527-partial-type-declarations)), and are subject to a number of restrictions.

Partial constructors may be defined in one part of a type declaration and implemented in another.

The identifier `partial` is recognized as a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) in a constructor declaration only if it appears immediately before the *constructor_declarator*.

There are two kinds of partial constructor declarations: If the body of the constructor declaration is a semicolon and the event has no `extern` modifier, the declaration is said to be a ***defining partial constructor declaration***. If the body is other than a semicolon, the declaration is said to be an ***implementing partial constructor declaration***. Across the parts of a type declaration, there shall be only one defining partial constructor declaration with a given signature, and there shall be one implementing partial constructor declaration with a given signature. If an implementing partial constructor declaration is given, a corresponding defining partial constructor declaration shall exist, and the declarations shall match as specified in the following:

1. Type and ref kind differences between partial declarations which are significant to the runtime result in a compile-time error.
2. Differences in tuple element names between partial declarations result in a compile-time error.
3. The declarations shall have the same modifiers, though the modifiers may appear in a different order; however, this does not apply to the `extern` modifier, which may only appear on the implementing declaration.
4. All other syntactic differences in the signatures of partial declarations result in a compile-time warning, with the following exceptions:
- Attribute lists need not match.
- Nullable context differences (such as oblivious vs. annotated) do not cause warnings.
- Default parameter values need not match, but a warning shall be reported when the implementing constructor declaration has default parameter values (because those would be ignored since only the defining declaration participates in lookup).
5. A warning shall occur when parameter names differ across defining and implementing constructor declarations.
6. Nullability differences which do not involve oblivious nullability result in warnings.

Partial constructors are useful for allowing one part of a type declaration to customize the behavior of another part, e.g., one that is generated by a tool.

The partial constructor gives rise to a constructor declaration similar to the implementing partial constructor declaration except for the following:

- The `partial` modifier is not included.

- The attributes in the resulting constructor declaration are the combined attributes of the defining and the implementing partial constructor declarations in unspecified order. Duplicates are not removed.

- 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 constructor declaration in unspecified order. Duplicates are not removed.

## 15.12 Static constructors

A ***static constructor*** is a member that implements the actions required to initialize a closed class. Static constructors are declared using *static_constructor_declaration*s:
Expand Down
4 changes: 2 additions & 2 deletions standard/documentation-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Although developers are free to create their own set of tags, a recommended set

Note carefully that the documentation file does not provide full information about the type and members (for example, it does not contain any type information). To get such information about a type or member, the documentation file must be used in conjunction with reflection on the type or member.

A partial type, partial method, partial property, or partial indexer can be declared in multiple parts, each of which can be in one or more compilation units, and each of which can have one or more documentation comments. A partial method, partial property, or partial indexer typically has a “defining partial declaration” and an “implementing partial declaration.”
A partial type, partial method, partial property, partial indexer, partial event, or partial constructor can be declared in multiple parts, each of which can be in one or more compilation units, and each of which can have one or more documentation comments. A partial method, partial property, partial indexer, partial event, or partial constructor typically has a “defining partial declaration” and an “implementing partial declaration.”

For a partial type, the document comments that apply directly to that type, if any, from each of its parts, are all written to the documentation file in some unspecified order.

For a partial method, partial property, or partial indexer:
For a partial method, partial property, partial indexer, partial event, or partial constructor:

- If a defining partial declaration has no corresponding implementing partial declaration, any documentation comments in that defining partial declaration are ignored (as that declaration will be removed).
- Otherwise, if the implementing partial declaration has any documentation comments, they are written to the documentation file, and any documentation comments in the defining partial declaration are ignored.
Expand Down
Loading