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/interfaces.md
+24-16Lines changed: 24 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ If a generic interface is declared in multiple parts ([§15.2.3](classes.md#1523
94
94
95
95
#### 19.2.3.2 Variance safety
96
96
97
-
The occurrence of variance annotations in the type parameter list of a type restricts the places where types can occur within the type declaration. However, these restrictions do not apply to occurrences of types within a declaration of a static member.
97
+
The occurrence of variance annotations in the type parameter list of a type restricts the places where types can occur within the type declaration. However, these restrictions do not apply to occurrences of types within a declaration of a non-virtual, non-abstract static member.
98
98
99
99
A type `T` is ***output-unsafe*** if one of the following holds:
This clause augments the description of members in classes ([§15.3](classes.md#153-class-members)) with the differences and restrictions for interfaces:
236
+
This subclause augments the description of members in classes ([§15.3](classes.md#153-class-members)) with the differences and restrictions for interfaces:
237
237
238
238
- A *finalizer_declaration* is not allowed.
239
239
- Instance constructors, *constructor_declaration*s, are not allowed.
240
240
- All interface members implicitly have public access; however, an explicit access modifier ([§7.5.2](basic-concepts.md#752-declared-accessibility)) is permitted except on static constructors ([§15.12](classes.md#1512-static-constructors)).
241
-
- The `abstract` modifier is implied for interface function members ([§12.6](expressions.md#126-function-members)) without bodies; that modifier may be given explicitly.
242
-
- An interface instance function member whose declaration includes a body is an implicitly `virtual` member unless the `sealed` or `private` modifier is used. The `virtual` modifier may be given explicitly.
241
+
- The `abstract` modifier is implied for interface instance function members ([§12.6](expressions.md#126-function-members)) without bodies; that modifier may be given explicitly. For interface static function members without bodies the `abstract` modifier shall be present.
242
+
- An interface instance function member whose declaration includes a body is an implicitly `virtual` member unless the `sealed` or `private` modifier is used. The `virtual` modifier may be given explicitly. An interface static member whose declaration includes a body may have a `virtual` modifier.
243
243
- A `private` or `sealed` function member of an interface shall have a body.
244
-
- A `private` function member shall not have the modifier `sealed`.
244
+
- A `private`instance function member shall not have the modifier `sealed`.
245
245
- A derived interface may override an abstract or virtual member declared in a base interface.
246
246
- An explicitly implemented function member shall not have the modifier `sealed`.
247
247
@@ -429,7 +429,7 @@ A virtual method with implementation declared in an interface may be overridden
429
429
430
430
### 19.4.4 Interface properties
431
431
432
-
Thisclauseaugmentsthedescriptionofpropertiesinclasses [§15.7](classes.md#157-properties) for properties declared in interfaces.
432
+
Thissubclauseaugmentsthedescriptionofpropertiesinclasses [§15.7](classes.md#157-properties) for properties declared in interfaces.
433
433
434
434
Interface properties are declared using *property_declaration*s ([§15.7.1](classes.md#1571-general)) withthefollowingadditionalrules:
435
435
@@ -440,25 +440,27 @@ Interface properties are declared using *property_declaration*s ([§15.7.1](clas
- Aninterfaceinstancemethoddeclarationthathasablockbodyorexpressionbodyasa *method_body* is `virtual`; the `virtual` modifierisnotrequired, butisallowed. Forastaticmethodthe `virtual` modifierispermitted.
444
+
- Aninstance *property_declaration* thathasnoimplementationis `abstract`; the `abstract` modifierisnotrequired, butisallowed. Itis *never* consideredtobeanautomaticallyimplementedproperty ([§15.7.4](classes.md#1574-automatically-implemented-properties)). However, the `abstract` modifiershallbepresentifastaticpropertyistobeabstract.
445
+
- A *property_declaration* maycontainthe `sealed` modifier.
445
446
446
447
### 19.4.5 Interface events
447
448
448
-
Thisclauseaugmentsthedescriptionofeventsinclasses [§15.8](classes.md#158-events) for events declared in interfaces.
449
+
Thissubclauseaugmentsthedescriptionofeventsinclasses [§15.8](classes.md#158-events) for events declared in interfaces.
449
450
450
451
Interface events are declared using *event_declaration*s ([§15.8.1](classes.md#1581-general)), withthefollowingadditionalrules:
451
452
452
453
-*event_modifier*shallnotinclude `override`.
453
454
-Aderivedinterfacemay implement an abstract interface event declared in a base interface ([§15.8.5](classes.md#1585-virtual-sealed-override-and-abstract-accessors)).
454
455
- It is a compile-time error for *variable_declarators* in an instance *event_declaration* to contain any *variable_initializer*s.
455
-
- An instance event with the `virtual` or `sealed` modifiers must declare accessors. It is *never* considered to be an automatically implemented field-like event ([§15.8.2](classes.md#1582-field-like-events)).
456
-
- An instance event with the `abstract` modifier must not declare accessors.
456
+
- An instance event with the `virtual` or `sealed` modifiers shall declare accessors. It is *never* considered to be an automatically implemented field-like event ([§15.8.2](classes.md#1582-field-like-events)).
457
+
- An instance event with the `abstract` modifier shall not declare accessors.
458
+
- A static event may have `abstract`, `virtual`, and `sealed` modifiers.
457
459
- The type of an interface event shall be input-safe.
458
460
459
461
### 19.4.6 Interface indexers
460
462
461
-
This clause augments the description of indexers in classes [§15.9](classes.md#159-indexers) for indexers declared in interfaces.
463
+
This sub clause augments the description of indexers in classes [§15.9](classes.md#159-indexers) for indexers declared in interfaces.
462
464
463
465
Interface indexers are declared using *indexer_declaration*s ([§15.9](classes.md#159-indexers)), with the following additional rules:
464
466
@@ -474,15 +476,19 @@ Interface indexers are declared using *indexer_declaration*s ([§15.9](classes.m
474
476
475
477
### 19.4.7 Interface operators
476
478
477
-
This clause augments the description of *operator_declaration* members in classes [§15.10](classes.md#1510-operators) for operators declared in interfaces.
479
+
This subclause augments the description of *operator_declaration* members in classes [§15.10](classes.md#1510-operators) for operators declared in interfaces.
478
480
479
481
For an *operator_declaration* in an interface the *operator_body* shall only be a block body ([§15.6.1](classes.md#1561-general)) or an expression body ([§15.6.1](classes.md#1561-general)).
480
482
481
-
It is a compile-time error for an interface to declare a conversion, equality, or inequality operator.
483
+
A static *operator_declaration* may have `abstract`, `virtual`, and `sealed` modifiers.
484
+
485
+
In the context of a class or struct, at least one of the *fixed_parameter*s in a *unary_operator_declarator* and *binary_operator_declarator* is required to have type `T` or `T?`, where `T` is the instance type of the enclosing type. This requirement is relaxed in the context of an interface in that a restricted operand is allowed to be of a type parameter that counts as “the instance type of the enclosing type.” In order for a type parameter `T` to count as that it shall meet the following requirements:
486
+
- `T` isadirecttypeparameterontheinterfaceinwhichtheoperatordeclarationoccurs, and
487
+
- `T` isdirectlyconstrainedbytheinstancetype; i.e., thesurroundinginterfacewith its own type parameters used as type arguments.
482
488
483
489
### 19.4.8 Interface static constructors
484
490
485
-
This clause augments the description of static constructors in classes [§15.12](classes.md#1512-static-constructors) for static constructors declared in interfaces.
491
+
This subclause augments the description of static constructors in classes [§15.12](classes.md#1512-static-constructors) for static constructors declared in interfaces.
486
492
487
493
The static constructor for a closed ([§8.4.3](types.md#843-open-and-closed-types)) interface executes at most once in a given application domain. The execution of a static constructor is triggered by the first of the following actions to occur within an application domain:
488
494
@@ -498,7 +504,7 @@ To initialize a new closed interface type, first a new set of static fields for
@@ -949,6 +955,8 @@ The qualified interface member name of an explicit interface member implementati
949
955
>
950
956
> *end example*
951
957
958
+
An explicit interface member implementation that implements a static member shall itself be static.
959
+
952
960
### 19.6.3 Uniqueness of implemented interfaces
953
961
954
962
The interfaces implemented by a generic type declaration shall remain unique for all possible constructed types. Without this rule, it would be impossible to determine the correct method to call for certain constructed types.
0 commit comments