Skip to content

Commit 98e9bd4

Browse files
authored
Fix examples (#727)
* Make all example tests pass (Currently 455 of them.) * Reformat all examples
1 parent 4166bc5 commit 98e9bd4

File tree

14 files changed

+55
-59
lines changed

14 files changed

+55
-59
lines changed

standard/attributes.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,8 @@ When an optional parameter is annotated with one of the caller-info attributes,
776776
777777
> *Example*:
778778
>
779-
> <!-- Example: {template:"code-in-class-lib", name:"Caller-infoAttributes"} -->
779+
> <!-- Example: {template:"code-in-class-lib", name:"CallerInfoAttributes"} -->
780780
> ```csharp
781-
> ...
782-
>
783781
> public void Log(
784782
> [CallerLineNumber] int line = -1,
785783
> [CallerFilePath] string path = null,
@@ -852,7 +850,7 @@ For interoperation with other languages, an indexer may be implemented using ind
852850
853851
> *Example*: By default, an indexer’s name is `Item`. This can be overridden, as follows:
854852
>
855-
> <!-- Example: {template:"code-in-class-lib", name:"AttributesForInteroperation", replaceEllipsis:true, customEllipsisReplacements: ["return 0;", ""]} -->
853+
> <!-- Example: {template:"code-in-class-lib", name:"AttributesForInteroperation", replaceEllipsis:true, customEllipsisReplacements:["return 0;",""]} -->
856854
> ```csharp
857855
> [System.Runtime.CompilerServices.IndexerName("TheItem")]
858856
> public int this[int index]

standard/basic-concepts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ The behavior of the garbage collector can be controlled, to some degree, via sta
968968
969969
> *Example*: Since the garbage collector is allowed wide latitude in deciding when to collect objects and run finalizers, a conforming implementation might produce output that differs from that shown by the following code. The program
970970
>
971-
> <!-- Example: {template:"standalone-console",name:"MemoryManagement1", ignoreOutput:true} -->
971+
> <!-- Example: {template:"standalone-console", name:"MemoryManagement1", ignoreOutput:true} -->
972972
> <!-- Maintenance Note: The behavior of this example is implementation-defined. As such, the metadata does *not* compare test output with any ```console block. -->
973973
> ```csharp
974974
> class A
@@ -1023,7 +1023,7 @@ The behavior of the garbage collector can be controlled, to some degree, via sta
10231023
>
10241024
> In subtle cases, the distinction between “eligible for finalization” and “eligible for collection” can be important. For example,
10251025
>
1026-
> <!-- Example: {template:"standalone-console",name:"MemoryManagement2", ignoreOutput:true} -->
1026+
> <!-- Example: {template:"standalone-console", name:"MemoryManagement2", ignoreOutput:true} -->
10271027
> <!-- Maintenance Note: The behavior of this example is implementation-defined. As such, the metadata does *not* compare test output with any ```console block. -->
10281028
> ```csharp
10291029
> class A

standard/classes.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ Nested types can be declared in multiple parts by using the `partial` modifier.
698698
>
699699
> When the two parts above are compiled together, the resulting code behaves as if the class had been written as a single unit, as follows:
700700
>
701-
> <!-- Example: {template:"standalone-lib-without-using", name:"PartialDeclarations2", replaceEllipsis:true, additionalFiles:["Order.cs"], expectedWarnings:["CS0169","CS0169","CS0169","CS0649"]} -->
701+
> <!-- Example: {template:"standalone-lib-without-using", name:"PartialDeclarations2", replaceEllipsis:true, expectedWarnings:["CS0169","CS0169","CS0169","CS0649"], additionalFiles:["Order.cs"]} -->
702702
> ```csharp
703703
> public class Customer
704704
> {
@@ -837,7 +837,7 @@ The non-inherited members of a constructed type are obtained by substituting, fo
837837
838838
> *Example*: Given the generic class declaration
839839
>
840-
> <!-- Example: {template:"standalone-lib-without-using", name:"MembersOfConstructedTypes", replaceEllipsis:true, customEllipsisReplacements: [null, "return default;", null, "return 0;"], expectedWarnings:["CS0649"]} -->
840+
> <!-- Example: {template:"standalone-lib-without-using", name:"MembersOfConstructedTypes", replaceEllipsis:true, customEllipsisReplacements:[null,"return default;",null,"return 0;"], expectedWarnings:["CS0649"]} -->
841841
> ```csharp
842842
> class Gen<T,U>
843843
> {
@@ -3308,8 +3308,8 @@ Unlike public fields, properties provide a separation between an object’s inte
33083308
> this.caption = caption;
33093309
> }
33103310
>
3311-
> public int X => location.x;
3312-
> public int Y => location.y;
3311+
> public int X => location.X;
3312+
> public int Y => location.Y;
33133313
> public Point Location => location;
33143314
> public string Caption => caption;
33153315
> }
@@ -3774,7 +3774,7 @@ In an operation of the form `x += y` or `x –= y`, when `x` is an event the
37743774

37753775
> *Example*: The following example shows how event handlers are attached to instances of the `Button` class:
37763776
>
3777-
> <!-- Example: {template:"standalone-lib-without-using", name:"Events", replaceEllipsis:true, additionalFiles:["Control.cs","Graphics.cs","Rectangle.cs","Point.cs","Form.cs"], expectedWarnings:["CS0067"]} -->
3777+
> <!-- Example: {template:"standalone-lib-without-using", name:"Events", replaceEllipsis:true, expectedWarnings:["CS0067"], additionalFiles:["Control.cs","Graphics.cs","Rectangle.cs","Point.cs","Form.cs"]} -->
37783778
> ```csharp
37793779
> public delegate void EventHandler(object sender, EventArgs e);
37803780
>
@@ -3861,7 +3861,7 @@ When compiling a field-like event, the compiler automatically creates storage to
38613861
38623862
> *Note*: Thus, an instance event declaration of the form:
38633863
>
3864-
> <!-- Example: {template:"standalone-lib-without-using", name:"FieldlikeEvents2", additionalFiles:["D.cs"], expectedWarnings:["CS0067"]} -->
3864+
> <!-- Example: {template:"standalone-lib-without-using", name:"FieldlikeEvents2", expectedWarnings:["CS0067"], additionalFiles:["D.cs"]} -->
38653865
> ```csharp
38663866
> class X
38673867
> {
@@ -3871,7 +3871,7 @@ When compiling a field-like event, the compiler automatically creates storage to
38713871
>
38723872
> shall be compiled to something equivalent to:
38733873
>
3874-
> <!-- Example: {template:"standalone-lib-without-using", name:"FieldlikeEvents3", additionalFiles:["D.cs"], expectedWarnings:["CS0169"]} -->
3874+
> <!-- Example: {template:"standalone-lib-without-using", name:"FieldlikeEvents3", expectedWarnings:["CS0169"], additionalFiles:["D.cs"]} -->
38753875
> ```csharp
38763876
> class X
38773877
> {
@@ -4296,7 +4296,7 @@ The `true` and `false` unary operators require pair-wise declaration. A compile-
42964296

42974297
> *Example*: The following example shows an implementation and subsequent usage of operator++ for an integer vector class:
42984298
>
4299-
> <!-- Example: {template:"standalone-console-without-using", name:"UnaryOperators", replaceEllipsis:true, customEllipsisReplacements:[null,"get { return 0; }","get { return 0; } set {}"]} -->
4299+
> <!-- Example: {template:"standalone-console-without-using", name:"UnaryOperators", replaceEllipsis:true, customEllipsisReplacements:[null,"return 0;","return 0;",null]} -->
43004300
> ```csharp
43014301
> public class IntVector
43024302
> {
@@ -4393,7 +4393,7 @@ It is not possible to directly redefine a pre-defined conversion. Thus, conversi
43934393
43944394
> *Example*:
43954395
>
4396-
> <!-- Example: {template:"standalone-lib-without-using", name:"ConversionOperators2", replaceEllipsis:true, customEllipsisReplacements:["return default;", "return default;"]} -->
4396+
> <!-- Example: {template:"standalone-lib-without-using", name:"ConversionOperators2", replaceEllipsis:true, customEllipsisReplacements:["return default;","return default;"]} -->
43974397
> ```csharp
43984398
> struct Convertible<T>
43994399
> {
@@ -4417,7 +4417,7 @@ For all types but `object`, the operators declared by the `Convertible<T>` type
44174417
44184418
> *Example*:
44194419
>
4420-
> <!-- Example: {template:"standalone-console-without-using", name:"ConversionOperators3", additionalFiles:["ConvertibleT.cs"], expectedErrors:["CS0266"], expectedWarnings:["CS8321"]} -->
4420+
> <!-- Example: {template:"standalone-console-without-using", name:"ConversionOperators3", expectedErrors:["CS0266"], expectedWarnings:["CS8321"], additionalFiles:["ConvertibleT.cs"]} -->
44214421
> ```csharp
44224422
> void F(int i, Convertible<int> n)
44234423
> {
@@ -4430,7 +4430,7 @@ For all types but `object`, the operators declared by the `Convertible<T>` type
44304430
>
44314431
> However, for type `object`, pre-defined conversions hide the user-defined conversions in all cases but one:
44324432
>
4433-
> <!-- Example: {template:"standalone-console-without-using", name:"ConversionOperators4", additionalFiles:["ConvertibleT.cs"], expectedWarnings:["CS8321"]} -->
4433+
> <!-- Example: {template:"standalone-console-without-using", name:"ConversionOperators4", expectedWarnings:["CS8321"], additionalFiles:["ConvertibleT.cs"]} -->
44344434
> ```csharp
44354435
> void F(object o, Convertible<object> n)
44364436
> {

standard/conversions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ If dynamic binding of the conversion is not desired, the expression can be first
510510
>
511511
> The following illustrates explicit dynamic conversions:
512512
>
513-
> <!-- Example: {template:"standalone-console-without-using", name:"ExplicitDynamic2", additionalFiles:["CForConversions.cs"], expectedException:"InvalidCastException"} -->
513+
> <!-- Example: {template:"standalone-console-without-using", name:"ExplicitDynamic2", expectedException:"InvalidCastException", additionalFiles:["CForConversions.cs"]} -->
514514
> ```csharp
515515
> object o = "1";
516516
> dynamic d = "2";
@@ -808,7 +808,7 @@ Specifically, an anonymous function `F` is compatible with a delegate type `D`
808808
>
809809
> In the assignments
810810
>
811-
> <!-- Example: {template:"standalone-console-without-using", name:"AnonymousFunctionsConv3", additionalFiles:["R.cs"], expectedErrors:["CS0266","CS1662"], expectedWarnings:["CS1998"]} -->
811+
> <!-- Example: {template:"standalone-console-without-using", name:"AnonymousFunctionsConv3", expectedErrors:["CS0266","CS1662"], expectedWarnings:["CS1998"], additionalFiles:["R.cs"]} -->
812812
> ```csharp
813813
> Func<int,int> f1 = x => x + 1; // Ok
814814
> Func<int,double> f2 = x => x + 1; // Ok
@@ -900,7 +900,7 @@ The compile-time application of the conversion from a method group `E` to a del
900900

901901
> *Example*: The following demonstrates method group conversions:
902902
>
903-
> <!-- Example: {template:"standalone-lib-without-using", name:"MethodGroupConversions1", replaceEllipsis:true, customEllipsisReplacements: ["return null;"], expectedErrors:["CS0123","CS0123","CS0123"]} -->
903+
> <!-- Example: {template:"standalone-lib-without-using", name:"MethodGroupConversions1", replaceEllipsis:true, customEllipsisReplacements:["return null;"], expectedErrors:["CS0123","CS0123","CS0123"]} -->
904904
> ```csharp
905905
> delegate string D1(object o);
906906
> delegate object D2(string s);
@@ -954,7 +954,7 @@ A method group conversion can refer to a generic method, either by explicitly sp
954954
955955
> *Example*:
956956
>
957-
> <!-- Example: {template:"standalone-console-without-using", name:"MethodGroupConversions2", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"], expectedErrors:["CS0411"]} -->
957+
> <!-- Example: {template:"standalone-console-without-using", name:"MethodGroupConversions2", replaceEllipsis:true, customEllipsisReplacements:["return default;","return default;"], expectedErrors:["CS0411"]} -->
958958
> ```csharp
959959
> delegate int D(string s, int i);
960960
> delegate int E();

standard/delegates.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ This definition of consistency allows covariance in return type and contravarian
9292
9393
> *Example*:
9494
>
95-
> <!-- Example: {template:"standalone-lib-without-using", name:"DelegateCompatibility1", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;", "return;", "return default;", "return;", "return default;", "return default;"]} -->
95+
> <!-- Example: {template:"standalone-lib-without-using", name:"DelegateCompatibility1", replaceEllipsis:true, customEllipsisReplacements:["return default;","return default;","return;","return default;","return;","return default;","return default;"]} -->
9696
> ```csharp
9797
> delegate int D1(int i, double d);
9898
> delegate int D2(int c, double d);
@@ -122,7 +122,7 @@ This definition of consistency allows covariance in return type and contravarian
122122
<!-- markdownlint-enable MD028 -->
123123
> *Example*:
124124
>
125-
> <!-- Example: {template:"standalone-lib-without-using", name:"DelegateCompatibility2", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return default;"] } -->
125+
> <!-- Example: {template:"standalone-lib-without-using", name:"DelegateCompatibility2", replaceEllipsis:true, customEllipsisReplacements:["return default;","return default;"]} -->
126126
> ```csharp
127127
> delegate bool Predicate<T>(T value);
128128
>

standard/documentation-comments.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ This tag is used to set one or more lines of source code or program output in so
118118

119119
**Example:**
120120

121-
<!-- Example: {template:"standalone-lib-without-using", name:"TagCode", ignoredWarnings:["CS1591"], replaceEllipsis:true} -->
121+
<!-- Example: {template:"standalone-lib-without-using", name:"TagCode", replaceEllipsis:true, ignoredWarnings:["CS1591"]} -->
122122
```csharp
123123
public class Point
124124
{
@@ -167,7 +167,7 @@ where
167167

168168
**Example:**
169169

170-
<!-- Example: {template:"standalone-lib-without-using", name:"TagException", ignoredWarnings:["CS1591"], replaceEllipsis:true} -->
170+
<!-- Example: {template:"standalone-lib-without-using", name:"TagException", replaceEllipsis:true, ignoredWarnings:["CS1591"]} -->
171171
```csharp
172172
class MasterFileFormatCorruptException : System.Exception { ... }
173173
class MasterFileLockedOpenException : System.Exception { ... }
@@ -894,7 +894,7 @@ IDs:
894894

895895
**Properties and indexers**
896896

897-
<!-- Example: {template:"standalone-lib-without-using", name:"IDStringsPropertiesAndIndexers", replaceEllipsis:true, customEllipsisReplacements: ["return default;", "return;","return default;", "return;","return default;", "return;"], additionalFiles:["IProcess.cs"]} -->
897+
<!-- Example: {template:"standalone-lib-without-using", name:"IDStringsPropertiesAndIndexers", replaceEllipsis:true, customEllipsisReplacements:["return default;","return;","return default;","return;","return default;","return;"], additionalFiles:["IProcess.cs"]} -->
898898
```csharp
899899
namespace Acme
900900
{
@@ -936,7 +936,7 @@ IDs:
936936

937937
**Unary operators**
938938

939-
<!-- Example: {template:"standalone-lib-without-using", name:"IDStringsUnaryOps", replaceEllipsis:true, customEllipsisReplacements: ["return default;"], additionalFiles:["IProcess.cs"]} -->
939+
<!-- Example: {template:"standalone-lib-without-using", name:"IDStringsUnaryOps", replaceEllipsis:true, customEllipsisReplacements:["return default;"], additionalFiles:["IProcess.cs"]} -->
940940
```csharp
941941
namespace Acme
942942
{

standard/expressions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ When an initializer target refers to an indexer, the arguments to the indexer sh
22012201
>
22022202
> An instance of `Rectangle` can be created and initialized as follows:
22032203
>
2204-
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers2User", additionalFiles:["PointWithAutoProps.cs", "Rectangle.cs"]} -->
2204+
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers2User", additionalFiles:["PointWithAutoProps.cs","Rectangle.cs"]} -->
22052205
> ```csharp
22062206
> Rectangle r = new Rectangle
22072207
> {
@@ -2212,7 +2212,7 @@ When an initializer target refers to an indexer, the arguments to the indexer sh
22122212
>
22132213
> This has the same effect as
22142214
>
2215-
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers2UserB", additionalFiles:["PointWithAutoProps.cs", "Rectangle.cs"]} -->
2215+
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers2UserB", additionalFiles:["PointWithAutoProps.cs","Rectangle.cs"]} -->
22162216
> ```csharp
22172217
> Rectangle __r = new Rectangle();
22182218
> Point __p1 = new Point();
@@ -2241,7 +2241,7 @@ When an initializer target refers to an indexer, the arguments to the indexer sh
22412241
>
22422242
> the following construct can be used to initialize the embedded `Point` instances instead of assigning new instances:
22432243
>
2244-
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers3User", additionalFiles:["PointWithAutoProps.cs", "RectangleWithConstructorPointAllocation.cs"]} -->
2244+
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers3User", additionalFiles:["PointWithAutoProps.cs","RectangleWithConstructorPointAllocation.cs"]} -->
22452245
> ```csharp
22462246
> Rectangle r = new Rectangle
22472247
> {
@@ -2252,7 +2252,7 @@ When an initializer target refers to an indexer, the arguments to the indexer sh
22522252
>
22532253
> This has the same effect as
22542254
>
2255-
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers3UserB", additionalFiles:["PointWithAutoProps.cs", "RectangleWithConstructorPointAllocation.cs"]} -->
2255+
> <!-- Example: {template:"code-in-main-without-using", name:"ObjectInitializers3UserB", additionalFiles:["PointWithAutoProps.cs","RectangleWithConstructorPointAllocation.cs"]} -->
22562256
> ```csharp
22572257
> Rectangle __r = new Rectangle();
22582258
> __r.P1.X = 0;
@@ -4548,7 +4548,7 @@ Anonymous functions in an argument list participate in type inference and overlo
45484548
>
45494549
> The `Sum` methods could for example be used to compute sums from a list of detail lines in an order.
45504550
>
4551-
> <!-- Example: {template:"standalone-lib-without-using", name:"OverloadResolution2", replaceEllipsis:true, customEllipsisReplacements:["", "", "", "", "return default;"], ignoredWarnings:["CS0649"], additionalFiles:["ItemListT.cs"]} -->
4551+
> <!-- Example: {template:"standalone-lib-without-using", name:"OverloadResolution2", replaceEllipsis:true, customEllipsisReplacements:["","","","","return default;"], ignoredWarnings:["CS0649"], additionalFiles:["ItemListT.cs"]} -->
45524552
> ```csharp
45534553
> class Detail
45544554
> {
@@ -4708,7 +4708,7 @@ When not captured, there is no way to observe exactly how often a local variable
47084708
>
47094709
> However, when the declaration of `x` is moved outside the loop:
47104710
>
4711-
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables4", inferOutput: true} -->
4711+
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables4", inferOutput:true} -->
47124712
> ```csharp
47134713
> delegate void D();
47144714
>
@@ -4752,7 +4752,7 @@ If a for-loop declares an iteration variable, that variable itself is considered
47524752

47534753
> *Example*: Thus, if the example is changed to capture the iteration variable itself:
47544754
>
4755-
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables5", inferOutput: true} -->
4755+
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables5", inferOutput:true} -->
47564756
> ```csharp
47574757
> delegate void D();
47584758
>
@@ -4792,7 +4792,7 @@ It is possible for anonymous function delegates to share some captured variables
47924792

47934793
> *Example*: For example, if `F` is changed to
47944794
>
4795-
> <!-- Example: {template:"code-in-partial-class", name:"InstantiationOfLocalVariables6", IgnoredWarnings:["CS8321"], additionalFiles:["Caller.cs"], inferOutput: true} -->
4795+
> <!-- Example: {template:"code-in-partial-class", name:"InstantiationOfLocalVariables6", ignoredWarnings:["CS8321"], inferOutput:true, additionalFiles:["Caller.cs"]} -->
47964796
> ```csharp
47974797
> static D[] F()
47984798
> {
@@ -5971,7 +5971,7 @@ When a property or indexer declared in a *struct_type* is the target of an assig
59715971
>
59725972
> the assignments to `p.X`, `p.Y`, `r.A`, and `r.B` are permitted because `p` and `r` are variables. However, in the example
59735973
>
5974-
> <!-- Example: {template:"standalone-console", name:"SimpleAssignment4", additionalFiles:["PointStruct.cs","RectangleStruct.cs"], expectedErrors:["CS1612","CS1612","CS1612","CS1612"]} -->
5974+
> <!-- Example: {template:"standalone-console", name:"SimpleAssignment4", expectedErrors:["CS1612","CS1612","CS1612","CS1612"], additionalFiles:["PointStruct.cs","RectangleStruct.cs"]} -->
59755975
> ```csharp
59765976
> Rectangle r = new Rectangle();
59775977
> r.A.X = 10;

0 commit comments

Comments
 (0)