Skip to content

Commit 4f8c5ca

Browse files
authored
revise example metadata (#709)
1 parent b7e7e9a commit 4f8c5ca

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

standard/interfaces.md

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If the variance annotation is `out`, the type parameter is said to be ***covaria
8080

8181
> *Example*: In the following:
8282
>
83-
> <!-- Example: {template:"standalone-lib", name:"VariantTypeParameterLists"} -->
83+
> <!-- Example: {template:"standalone-lib-without-using", name:"VariantTypeParameterLists"} -->
8484
> ```csharp
8585
> interface C<out X, in Y, Z>
8686
> {
@@ -153,7 +153,7 @@ The ***base interfaces*** of an interface are the explicit base interfaces and t
153153

154154
> *Example*: In the following code
155155
>
156-
> <!-- Example: {template:"standalone-lib", name:"BaseInterfaces1"} -->
156+
> <!-- Example: {template:"standalone-lib-without-using", name:"BaseInterfaces1"} -->
157157
> ```csharp
158158
> interface IControl
159159
> {
@@ -181,7 +181,7 @@ Members inherited from a constructed generic type are inherited after type subst
181181
182182
> *Example*: In the following code
183183
>
184-
> <!-- Example: {template:"standalone-lib", name:"BaseInterfaces2"} -->
184+
> <!-- Example: {template:"standalone-lib-without-using", name:"BaseInterfaces2"} -->
185185
> ```csharp
186186
> interface IBase<T>
187187
> {
@@ -194,7 +194,7 @@ Members inherited from a constructed generic type are inherited after type subst
194194
> }
195195
> ```
196196
>
197-
> the interface IDerived inherits the Combine method after the type parameter `T` is replaced with `string[,]`.
197+
> the interface `IDerived` inherits the `Combine` method after the type parameter `T` is replaced with `string[,]`.
198198
>
199199
> *end example*
200200
@@ -273,7 +273,7 @@ These rules ensure that any covariant or contravariant usage of the interface re
273273

274274
> *Example*:
275275
>
276-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMethods1", expectedErrors:["CS1961"]} -->
276+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMethods1", expectedErrors:["CS1961"]} -->
277277
> ```csharp
278278
> interface I<out T>
279279
> {
@@ -285,7 +285,8 @@ These rules ensure that any covariant or contravariant usage of the interface re
285285
>
286286
> Were this restriction not in place it would be possible to violate type safety in the following manner:
287287
>
288-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceMethods2", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
288+
> <!-- Incomplete$Example: {template:"standalone-lib-without-using", name:"InterfaceMethods2", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
289+
> <!-- FIX: need to define I<T>, then perhaps break into 2 files, first one a standalone-lib, the second, code-in-class-lib. -->
289290
> ```csharp
290291
> class B {}
291292
> class D : B {}
@@ -373,7 +374,7 @@ For interfaces that are strictly single-inheritance (each interface in the inher
373374

374375
> *Example*: In the following code
375376
>
376-
> <!-- NeedsReviewExample: {template:"standalone-lib", name:"InterfaceMemberAccess1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
377+
> <!-- NeedsReview$Example: {template:"standalone-lib-without-using", name:"InterfaceMemberAccess1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
377378
> ```csharp
378379
> interface IList
379380
> {
@@ -407,7 +408,7 @@ For interfaces that are strictly single-inheritance (each interface in the inher
407408
<!-- markdownlint-enable MD028 -->
408409
> *Example*: In the following code
409410
>
410-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMemberAccess2"} -->
411+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMemberAccess2"} -->
411412
> ```csharp
412413
> interface IInteger
413414
> {
@@ -441,7 +442,7 @@ For interfaces that are strictly single-inheritance (each interface in the inher
441442
<!-- markdownlint-enable MD028 -->
442443
> *Example*: In the following code
443444
>
444-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMemberAccess3"} -->
445+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMemberAccess3"} -->
445446
> ```csharp
446447
> interface IBase
447448
> {
@@ -484,7 +485,7 @@ An interface member is sometimes referred to by its ***qualified interface membe
484485
485486
> *Example*: Given the declarations
486487
>
487-
> <!-- Example: {template:"standalone-lib", name:"QualifiedInterfaceMemberNames1"} -->
488+
> <!-- Example: {template:"standalone-lib-without-using", name:"QualifiedInterfaceMemberNames1"} -->
488489
> ```csharp
489490
> interface IControl
490491
> {
@@ -505,7 +506,7 @@ When an interface is part of a namespace, a qualified interface member name can
505506
506507
> *Example*:
507508
>
508-
> <!-- Example: {template:"standalone-lib", name:"QualifiedInterfaceMemberNames2"} -->
509+
> <!-- Example: {template:"standalone-lib-without-using", name:"QualifiedInterfaceMemberNames2"} -->
509510
> ```csharp
510511
> namespace System
511512
> {
@@ -528,7 +529,7 @@ Interfaces may be implemented by classes and structs. To indicate that a class o
528529
529530
> *Example*:
530531
>
531-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceImplementations1", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
532+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementations1", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"]} -->
532533
> ```csharp
533534
> interface ICloneable
534535
> {
@@ -553,7 +554,7 @@ A class or struct that directly implements an interface also implicitly implemen
553554
554555
> *Example*:
555556
>
556-
> <!-- Example: {template:"standalone-lib", name:"InterfaceImplementations2", replaceEllipsis:true} -->
557+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementations2", replaceEllipsis:true} -->
557558
> ```csharp
558559
> interface IControl
559560
> {
@@ -582,7 +583,7 @@ The base interfaces specified in a class declaration can be constructed interfac
582583
583584
> *Example*: The following code illustrates how a class can implement constructed interface types:
584585
>
585-
> <!-- Example: {template:"standalone-lib", name:"InterfaceImplementations3"} -->
586+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementations3"} -->
586587
> ```csharp
587588
> class C<U, V> {}
588589
> interface I1<V> {}
@@ -600,7 +601,7 @@ For purposes of implementing interfaces, a class or struct may declare ***explic
600601
601602
> *Example*:
602603
>
603-
> <!-- IncompleteExample: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations1", replaceEllipsis:true, expectedErrors:["CS0161","CS0161"]} -->
604+
> <!-- Example: {template:"standalone-lib-without-using", name:"ExplicitInterfaceMemberImplementations1", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "get { return default; }", "return;"]} -->
604605
> ```csharp
605606
> interface IList<T>
606607
> {
@@ -629,7 +630,7 @@ For purposes of implementing interfaces, a class or struct may declare ***explic
629630
<!-- markdownlint-enable MD028 -->
630631
> *Example*: In some cases, the name of an interface member might not be appropriate for the implementing class, in which case, the interface member may be implemented using explicit interface member implementation. A class implementing a file abstraction, for example, would likely implement a `Close` member function that has the effect of releasing the file resource, and implement the `Dispose` method of the `IDisposable` interface using explicit interface member implementation:
631632
>
632-
> <!-- Example: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations2"} -->
633+
> <!-- Example: {template:"standalone-lib-without-using", name:"ExplicitInterfaceMemberImplementations2"} -->
633634
> ```csharp
634635
> interface IDisposable
635636
> {
@@ -668,7 +669,7 @@ For an explicit interface member implementation to be valid, the class or struct
668669
669670
> *Example*: Thus, in the following class
670671
>
671-
> <!-- IncompleteExample: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations3", replaceEllipsis:true, expectedErrors:["CS0540"]} -->
672+
> <!-- Example: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations3", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"], expectedErrors:["CS0540"]} -->
672673
> ```csharp
673674
> class Shape : ICloneable
674675
> {
@@ -679,7 +680,7 @@ For an explicit interface member implementation to be valid, the class or struct
679680
>
680681
> the declaration of `IComparable.CompareTo` results in a compile-time error because `IComparable` is not listed in the base class list of `Shape` and is not a base interface of `ICloneable`. Likewise, in the declarations
681682
>
682-
> <!-- IncompleteExample: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations4", replaceEllipsis:true, expectedErrors:["CS0540"]} -->
683+
> <!-- Example: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations4", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"], expectedErrors:["CS0540"]} -->
683684
> ```csharp
684685
> class Shape : ICloneable
685686
> {
@@ -700,7 +701,7 @@ The qualified interface member name of an explicit interface member implementati
700701
701702
> *Example*: Thus, in the declarations
702703
>
703-
> <!-- Example: {template:"standalone-lib", name:"ExplicitInterfaceMemberImplementations5", replaceEllipsis:true} -->
704+
> <!-- Example: {template:"standalone-lib-without-using", name:"ExplicitInterfaceMemberImplementations5", replaceEllipsis:true} -->
704705
> ```csharp
705706
> interface IControl
706707
> {
@@ -729,7 +730,7 @@ The interfaces implemented by a generic type declaration shall remain unique for
729730
730731
> *Example*: Suppose a generic class declaration were permitted to be written as follows:
731732
>
732-
> <!-- Example: {template:"standalone-lib", name:"UniquenessOfImplementedInterfaces1", replaceEllipsis:true, expectedErrors:["CS0695"]} -->
733+
> <!-- Example: {template:"standalone-lib-without-using", name:"UniquenessOfImplementedInterfaces1", replaceEllipsis:true, expectedErrors:["CS0695"]} -->
733734
> ```csharp
734735
> interface I<T>
735736
> {
@@ -763,7 +764,7 @@ To determine if the interface list of a generic type declaration is valid, the f
763764
764765
It is possible for interfaces specified at different inheritance levels to unify:
765766
766-
<!-- Example: {template:"standalone-lib", name:"UniquenessOfImplementedInterfaces2", replaceEllipsis:true} -->
767+
<!-- Example: {template:"standalone-lib-without-using", name:"UniquenessOfImplementedInterfaces2", replaceEllipsis:true} -->
767768
```csharp
768769
interface I<T>
769770
{
@@ -796,7 +797,8 @@ When a generic method implicitly implements an interface method, the constraints
796797

797798
> *Example*: In the following code:
798799
>
799-
> <!-- Example: {template:"standalone-lib", name:"ImplementationOfGenericMethods1", replaceEllipsis:true, expectedErrors:["CS0425","CS0701"]} -->
800+
> <!-- Example: {template:"standalone-lib-without-using", name:"ImplementationOfGenericMethods1", replaceEllipsis:true, expectedErrors:["CS0425","CS0701"]} -->
801+
> <!-- Maintenance Note: A version of this type exists in additional-files as "ITTT.cs". As such, certain changes to this type definition might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
800802
> ```csharp
801803
> interface I<X, Y, Z>
802804
> {
@@ -815,7 +817,7 @@ When a generic method implicitly implements an interface method, the constraints
815817
>
816818
> the method `C.F<T>` implicitly implements `I<object,C,string>.F<T>`. In this case, `C.F<T>` is not required (nor permitted) to specify the constraint `T: object` since `object` is an implicit constraint on all type parameters. The method `C.G<T>` implicitly implements `I<object,C,string>.G<T>` because the constraints match those in the interface, after the interface type parameters are replaced with the corresponding type arguments. The constraint for method `C.H<T>` is an error because sealed types (`string` in this case) cannot be used as constraints. Omitting the constraint would also be an error since constraints of implicit interface method implementations are required to match. Thus, it is impossible to implicitly implement `I<object,C,string>.H<T>`. This interface method can only be implemented using an explicit interface member implementation:
817819
>
818-
> <!-- IncompleteExample: {template:"standalone-lib", name:"ImplementationOfGenericMethods2", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
820+
> <!-- Example: {template:"standalone-lib-without-using", name:"ImplementationOfGenericMethods2", replaceEllipsis:true, additionalFiles:["ITTT.cs"]} -->
819821
> ```csharp
820822
> class C : I<object, C, string>
821823
> {
@@ -852,7 +854,7 @@ Members of a constructed interface type are considered to have any type paramete
852854
853855
> *Example*: For example, given the generic interface declaration:
854856
>
855-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMapping1"} -->
857+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping1"} -->
856858
> ```csharp
857859
> interface I<T>
858860
> {
@@ -884,7 +886,7 @@ Notable implications of the interface-mapping algorithm are:
884886
885887
> *Example*: In the following code
886888
>
887-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceMapping3", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
889+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping3", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"]} -->
888890
> ```csharp
889891
> interface ICloneable
890892
> {
@@ -906,7 +908,7 @@ If a class or struct implements two or more interfaces containing a member with
906908
907909
> *Example*:
908910
>
909-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMapping4", replaceEllipsis:true} -->
911+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping4", replaceEllipsis:true} -->
910912
> ```csharp
911913
> interface IControl
912914
> {
@@ -932,7 +934,7 @@ If a class or struct implements an interface that contains hidden members, then
932934
933935
> *Example*:
934936
>
935-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMapping5"} -->
937+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping5"} -->
936938
> ```csharp
937939
> interface IBase
938940
> {
@@ -947,7 +949,8 @@ If a class or struct implements an interface that contains hidden members, then
947949
>
948950
> An implementation of this interface would require at least one explicit interface member implementation, and would take one of the following forms
949951
>
950-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceMapping6", replaceEllipsis:true, expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
952+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping6", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;", "return default;"], additionalFiles:["IBase.cs", "IDerived.cs"]} -->
953+
> <!-- Maintenance Note: A version of this type exists in additional-files as "IBase.cs" and "IDerived.cs". As such, certain changes to this type definition might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
951954
> ```csharp
952955
> class C1 : IDerived
953956
> {
@@ -972,7 +975,7 @@ When a class implements multiple interfaces that have the same base interface, t
972975
973976
> *Example*: In the following code
974977
>
975-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMapping7", replaceEllipsis:true} -->
978+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping7", replaceEllipsis:true} -->
976979
> ```csharp
977980
> interface IControl
978981
> {
@@ -1005,7 +1008,7 @@ The members of a base class participate in interface mapping.
10051008
10061009
> *Example*: In the following code
10071010
>
1008-
> <!-- Example: {template:"standalone-lib", name:"InterfaceMapping8"} -->
1011+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceMapping8"} -->
10091012
> ```csharp
10101013
> interface Interface1
10111014
> {
@@ -1036,7 +1039,8 @@ Without explicitly re-implementing an interface, a derived class cannot in any w
10361039
10371040
> *Example*: In the declarations
10381041
>
1039-
> <!-- Example: {template:"standalone-lib", name:"InterfaceImplementationInheritance1", replaceEllipsis:true} -->
1042+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementationInheritance1", replaceEllipsis:true} -->
1043+
> <!-- Maintenance Note: A version of these types exists in additional-files as "IControlControlTextBox1.cs". As such, certain changes to these type definitions might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
10401044
> ```csharp
10411045
> interface IControl
10421046
> {
@@ -1056,7 +1060,7 @@ Without explicitly re-implementing an interface, a derived class cannot in any w
10561060
>
10571061
> the `Paint` method in `TextBox` hides the `Paint` method in `Control`, but it does not alter the mapping of `Control.Paint` onto `IControl.Paint`, and calls to `Paint` through class instances and interface instances will have the following effects
10581062
>
1059-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceImplementationInheritance2", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
1063+
> <!-- Example: {template:"standalone-console-without-using", name:"InterfaceImplementationInheritance2", additionalFiles:["IControlControlTextBox1.cs"]} -->
10601064
> ```csharp
10611065
> Control c = new Control();
10621066
> TextBox t = new TextBox();
@@ -1074,7 +1078,8 @@ However, when an interface method is mapped onto a virtual method in a class, it
10741078
10751079
> *Example*: Rewriting the declarations above to
10761080
>
1077-
> <!-- Example: {template:"standalone-lib", name:"InterfaceImplementationInheritance3", replaceEllipsis:true} -->
1081+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementationInheritance3", replaceEllipsis:true} -->
1082+
> <!-- Maintenance Note: A version of these types exists in additional-files as "IControlControlTextBox2.cs". As such, certain changes to these type definitions might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
10781083
> ```csharp
10791084
> interface IControl
10801085
> {
@@ -1094,7 +1099,7 @@ However, when an interface method is mapped onto a virtual method in a class, it
10941099
>
10951100
> the following effects will now be observed
10961101
>
1097-
> <!-- IncompleteExample: {template:"standalone-lib", name:"InterfaceImplementationInheritance4", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
1102+
> <!-- Example: {template:"standalone-console-without-using", name:"InterfaceImplementationInheritance4", additionalFiles:["IControlControlTextBox2.cs"]} -->
10981103
> ```csharp
10991104
> Control c = new Control();
11001105
> TextBox t = new TextBox();
@@ -1112,7 +1117,7 @@ Since explicit interface member implementations cannot be declared virtual, it i
11121117
11131118
> *Example*:
11141119
>
1115-
> <!-- Example: {template:"standalone-lib", name:"InterfaceImplementationInheritance5", replaceEllipsis:true} -->
1120+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceImplementationInheritance5", replaceEllipsis:true} -->
11161121
> ```csharp
11171122
> interface IControl
11181123
> {
@@ -1143,7 +1148,7 @@ A re-implementation of an interface follows exactly the same interface mapping r
11431148
11441149
> *Example*: In the declarations
11451150
>
1146-
> <!-- Example: {template:"standalone-lib", name:"InterfaceRe-implementation1", replaceEllipsis:true} -->
1151+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceRe-implementation1", replaceEllipsis:true} -->
11471152
> ```csharp
11481153
> interface IControl
11491154
> {
@@ -1169,7 +1174,7 @@ Inherited public member declarations and inherited explicit interface member dec
11691174
11701175
> *Example*:
11711176
>
1172-
> <!-- Example: {template:"standalone-lib", name:"InterfaceRe-implementation2"} -->
1177+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceRe-implementation2"} -->
11731178
> ```csharp
11741179
> interface IMethods
11751180
> {
@@ -1202,7 +1207,7 @@ When a class implements an interface, it implicitly also implements all that int
12021207
12031208
> *Example*:
12041209
>
1205-
> <!-- Example: {template:"standalone-lib", name:"InterfaceRe-implementation3", replaceEllipsis:true} -->
1210+
> <!-- Example: {template:"standalone-lib-without-using", name:"InterfaceRe-implementation3", replaceEllipsis:true} -->
12061211
> ```csharp
12071212
> interface IBase
12081213
> {
@@ -1237,7 +1242,7 @@ Like a non-abstract class, an abstract class shall provide implementations of al
12371242
12381243
> *Example*:
12391244
>
1240-
> <!-- Example: {template:"standalone-lib", name:"AbstractClassesAndInterfaces1"} -->
1245+
> <!-- Example: {template:"standalone-lib-without-using", name:"AbstractClassesAndInterfaces1"} -->
12411246
> ```csharp
12421247
> interface IMethods
12431248
> {
@@ -1260,7 +1265,7 @@ Explicit interface member implementations cannot be abstract, but explicit inter
12601265
12611266
> *Example*:
12621267
>
1263-
> <!-- Example: {template:"standalone-lib", name:"AbstractClassesAndInterfaces2"} -->
1268+
> <!-- Example: {template:"standalone-lib-without-using", name:"AbstractClassesAndInterfaces2"} -->
12641269
> ```csharp
12651270
> interface IMethods
12661271
> {

0 commit comments

Comments
 (0)