Skip to content

Commit 44d13e6

Browse files
authored
Example metadata: namespaces.md (#711)
* revise example metadata * fix html comment formatting
1 parent 8db316d commit 44d13e6

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

standard/namespaces.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The *namespace_member_declaration*s of each compilation unit of a program contri
2929

3030
> *Example*:
3131
>
32-
> <!-- Example: {template:"standalone-lib", name:"CompilationUnits"} -->
32+
> <!-- Example: {template:"standalone-lib-without-using", name:"CompilationUnits"} -->
3333
> ```csharp
3434
> // File A.cs:
3535
> class A {}
@@ -70,7 +70,7 @@ The *qualified_identifier* of a *namespace_declaration* may be a single identifi
7070

7171
> *Example*:
7272
>
73-
> <!-- Example: {template:"standalone-lib", name:"NamespaceDeclarations1"} -->
73+
> <!-- Example: {template:"standalone-lib-without-using", name:"NamespaceDeclarations1"} -->
7474
> ```csharp
7575
> namespace N1.N2
7676
> {
@@ -81,7 +81,7 @@ The *qualified_identifier* of a *namespace_declaration* may be a single identifi
8181
>
8282
> is semantically equivalent to
8383
>
84-
> <!-- Example: {template:"standalone-lib", name:"NamespaceDeclarations2"} -->
84+
> <!-- Example: {template:"standalone-lib-without-using", name:"NamespaceDeclarations2"} -->
8585
> ```csharp
8686
> namespace N1
8787
> {
@@ -99,7 +99,7 @@ Namespaces are open-ended, and two namespace declarations with the same fully qu
9999
100100
> *Example*: In the following code
101101
>
102-
> <!-- Example: {template:"standalone-lib", name:"NamespaceDeclarations3"} -->
102+
> <!-- Example: {template:"standalone-lib-without-using", name:"NamespaceDeclarations3"} -->
103103
> ```csharp
104104
> namespace N1.N2
105105
> {
@@ -138,7 +138,8 @@ An error occurs if a program declares an extern alias for which no external defi
138138
139139
> *Example*: The following program declares and uses two extern aliases, `X` and `Y`, each of which represent the root of a distinct namespace hierarchy:
140140
>
141-
> <!-- IncompleteExample: {template:"standalone-lib", name:"ExternAliasDirectives", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
141+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"ExternAliasDirectives", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
142+
> <!-- FIX: I got this to work outside the test framework. 1. The external definitions are in files ExternAliasX.cs and ExternAliasY.cs in the additional-files folder. 2. We need a DLL for each of these compiled using csc ExternAliasX.cs -t:library and csc ExternAliasY.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs -t:library -r:X=ExternAliasX.dll -r:Y=ExternAliasY.dll, where the two references must include the path to the DLLs. -->
142143
> ```csharp
143144
> extern alias X;
144145
> extern alias Y;
@@ -191,7 +192,7 @@ Within global attributes and member declarations in a compilation unit or namesp
191192
192193
> *Example*:
193194
>
194-
> <!-- Example: {template:"standalone-lib", name:"UsingAliasDirectives1"} -->
195+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives1"} -->
195196
> ```csharp
196197
> namespace N1.N2
197198
> {
@@ -207,7 +208,7 @@ Within global attributes and member declarations in a compilation unit or namesp
207208
>
208209
> Above, within member declarations in the `N3` namespace, `A` is an alias for `N1.N2.A`, and thus class `N3.B` derives from class `N1.N2.A`. The same effect can be obtained by creating an alias `R` for `N1.N2` and then referencing `R.A`:
209210
>
210-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives2", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
211+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives2", additionalFiles:["N1N2.cs"]} -->
211212
> ```csharp
212213
> namespace N3
213214
> {
@@ -223,6 +224,8 @@ Within using directives, global attributes and member declarations in a compilat
223224
224225
> *Example*: For example:
225226
>
227+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives3", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
228+
> <!-- FIX: I got this to work outside the test framework. 1. The external definition is in file ExternAliasN2.cs in the additional-files folder. 2. We need a DLL for this compiled using csc ExternAliasN2.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs -t:library -r:X=ExternAliasN2.dll, where the reference must include the path to the DLL. -->
226229
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives3", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
227230
> ```csharp
228231
> namespace N1
@@ -235,7 +238,8 @@ Within using directives, global attributes and member declarations in a compilat
235238
>
236239
> Above, within member declarations in the `N1` namespace, `N2` is an alias for some namespace whose definition is external to the source code of the program. Class `N1.B` derives from class `N2.A`. The same effect can be obtained by creating an alias `A` for `N2.A` and then referencing `A`:
237240
>
238-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives4", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
241+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives4", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
242+
> <!-- FIX: I got this to work outside the test framework. 1. The external definition is in file ExternAliasN2.cs in the additional-files folder. 2. We need a DLL for this compiled using csc ExternAliasN2.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs -t:library -r:X=ExternAliasN2.dll, where the reference must include the path to the DLL. -->
239243
> ```csharp
240244
> namespace N1
241245
> {
@@ -253,7 +257,8 @@ An *extern_alias_directive* or *using_alias_directive* makes an alias available
253257
254258
> *Example*: In the following code
255259
>
256-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives5", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
260+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives5", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
261+
> <!-- FIX: I got this to work outside the test framework. 1. The external definition is in file ExternAliasR1.cs in the additional-files folder. 2. We need a DLL for this compiled using csc ExternAliasR1.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs N1N2.cs -t:library -r:X=ExternAliasR1.dll, where the reference must include the path to the DLL. -->
257262
> ```csharp
258263
> namespace N3
259264
> {
@@ -270,7 +275,8 @@ An *extern_alias_directive* or *using_alias_directive* makes an alias available
270275
>
271276
> the scopes of the alias directives that introduce `R1` and `R2` only extend to member declarations in the namespace body in which they are contained, so `R1` and `R2` are unknown in the second namespace declaration. However, placing the alias directives in the containing compilation unit causes the alias to become available within both namespace declarations:
272277
>
273-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives6", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
278+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives6", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
279+
> <!-- FIX: I got this to work outside the test framework. 1. The external definition is in file ExternAliasR1.cs in the additional-files folder. 2. We need a DLL for this compiled using csc ExternAliasR1.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs N1N2.cs -t:library -r:X=ExternAliasR1.dll, where the reference must include the path to the DLL. -->
274280
> ```csharp
275281
> extern alias R1;
276282
>
@@ -293,7 +299,8 @@ Each *extern_alias_directive* or *using_alias_directive* in a *compilation_unit*
293299
294300
> *Example*:
295301
>
296-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives7", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
302+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives7", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
303+
> <!-- FIX: I got this to work outside the test framework. 1. The external definitions are in files ExternAliasA.cs and ExternAliasB.cs in the additional-files folder. 2. We need a DLL for each of these compiled using csc ExternAliasA.cs -t:library and csc ExternAliasB.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs N1N2.cs -t:library -r:X=ExternAliasA.dll -r:Y=ExternAliasB.dll, where the two references must include the path to the DLLs. -->
297304
> ```csharp
298305
> extern alias A;
299306
> extern alias B;
@@ -307,7 +314,7 @@ Each *extern_alias_directive* or *using_alias_directive* in a *compilation_unit*
307314
>
308315
> When an alias name matches the name of a member of a namespace, usage of either must be appropriately qualified:
309316
>
310-
> <!-- Example: {template:"standalone-lib", name:"UsingAliasDirectives8", expectedErrors:["CS0576","CS0576"]} -->
317+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives8", expectedErrors:["CS0576","CS0576"]} -->
311318
> ```csharp
312319
> namespace N1.N2
313320
> {
@@ -340,7 +347,7 @@ Just like regular members, names introduced by *alias_directives* are hidden by
340347
341348
> *Example*: In the following code
342349
>
343-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives9", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
350+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives9", additionalFiles:["N1N2.cs"], expectedErrors:["CS0426"]} -->
344351
> ```csharp
345352
> using R = N1.N2;
346353
>
@@ -359,7 +366,8 @@ The order in which *extern_alias_directive*s are written has no significance. Li
359366
360367
> *Example*: In the following code
361368
>
362-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives10", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
369+
> <!-- ExternalRef$Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives10", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
370+
> <!-- FIX: I got this to work outside the test framework. 1. The external definition is in file ExternAliasE.cs in the additional-files folder. 2. We need a DLL for this compiled using csc ExternAliasE.cs -t:library 3. The Library.cs file needs to be compiled using csc Library.cs -t:library -r:E=ExternAliasE.dll, where the reference must include the path to the DLL. -->
363371
> ```csharp
364372
> namespace N1.N2 {}
365373
>
@@ -384,7 +392,7 @@ Accessing a namespace or type through an alias yields exactly the same result as
384392
385393
> *Example*: Given
386394
>
387-
> <!-- Example: {template:"standalone-lib", name:"UsingAliasDirectives11", ignoredWarnings:["CS0169"]} -->
395+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives11", ignoredWarnings:["CS0169"]} -->
388396
> ```csharp
389397
> namespace N1.N2
390398
> {
@@ -413,7 +421,7 @@ Although each part of a partial type ([§14.2.7](classes.md#1427-partial-declara
413421
414422
> *Example*:
415423
>
416-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingAliasDirectives12", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
424+
> <!-- Example: {template:"standalone-lib", name:"UsingAliasDirectives12", additionalFiles:["WidgetsLinkedList.cs"], ignoredWarnings:["CS0169"]} -->
417425
> ```csharp
418426
> namespace N
419427
> {
@@ -442,7 +450,7 @@ Using aliases can name a closed constructed type, but cannot name an unbound gen
442450
443451
> *Example*:
444452
>
445-
> <!-- BrokenExample: {template:"standalone-lib", name:"UsingAliasDirectives13", expectedErrors:["CS1002","CS0116","CS1022","CS1022"]} -->
453+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingAliasDirectives13", expectedErrors:["CS0305","CS0305","CS0116","CS0246","CS0246","CS1002","CS1022","CS1022"]} -->
446454
> ```csharp
447455
> namespace N1
448456
> {
@@ -477,7 +485,7 @@ Within member declarations in a compilation unit or namespace body that contains
477485

478486
> *Example*:
479487
>
480-
> <!-- Example: {template:"standalone-lib", name:"UsingNamespaceDirectives1"} -->
488+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives1"} -->
481489
> ```csharp
482490
> namespace N1.N2
483491
> {
@@ -500,7 +508,7 @@ A *using_namespace_directive* imports the types contained in the given namespace
500508
501509
> *Example*: In the following code
502510
>
503-
> <!-- Example: {template:"standalone-lib", name:"UsingNamespaceDirectives2", expectedErrors:["CS0246"]} -->
511+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives2", expectedErrors:["CS0246"]} -->
504512
> ```csharp
505513
> namespace N1.N2
506514
> {
@@ -522,7 +530,7 @@ Unlike a *using_alias_directive*, a *using_namespace_directive* may import types
522530
523531
> *Example*:
524532
>
525-
> <!-- Example: {template:"standalone-lib", name:"UsingNamespaceDirectives3"} -->
533+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives3"} -->
526534
> ```csharp
527535
> namespace N1.N2
528536
> {
@@ -545,7 +553,7 @@ Because names may be ambiguous when more than one imported namespace introduces
545553
546554
> *Example*: In the following code
547555
>
548-
> <!-- Example: {template:"standalone-lib", name:"UsingNamespaceDirectives4", expectedErrors:["CS0104"]} -->
556+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives4", expectedErrors:["CS0104"]} -->
549557
> ```csharp
550558
> namespace N1
551559
> {
@@ -568,7 +576,7 @@ Because names may be ambiguous when more than one imported namespace introduces
568576
>
569577
> both `N1` and `N2` contain a member `A`, and because `N3` imports both, referencing `A` in `N3` is a compile-time error. In this situation, the conflict can be resolved either through qualification of references to `A`, or by introducing a *using_alias_directive* that picks a particular `A`. For example:
570578
>
571-
> <!-- IncompleteExample: {template:"standalone-lib", name:"UsingNamespaceDirectives5", replaceEllipsis:true, expectedOutput:["x", "x", "x"], expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
579+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives5", additionalFiles:["N1.cs", "N2.cs"]} -->
572580
> ```csharp
573581
> namespace N3
574582
> {
@@ -586,7 +594,7 @@ Furthermore, when more than one namespace or type imported by *using_namespace_d
586594
587595
> *Example*:
588596
>
589-
> <!-- Example: {template:"standalone-lib", name:"UsingNamespaceDirectives6", expectedErrors:["CS0229"], ignoredWarnings:["CS0649"]} -->
597+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingNamespaceDirectives6", expectedErrors:["CS0229"], ignoredWarnings:["CS0649"]} -->
590598
> ```csharp
591599
> namespace N1
592600
> {
@@ -636,7 +644,7 @@ Within member declarations in a compilation unit or namespace body that contains
636644

637645
> *Example*:
638646
>
639-
> <!-- Example: {template:"standalone-lib", name:"UsingStaticDirectives1"} -->
647+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingStaticDirectives1"} -->
640648
> ```csharp
641649
> namespace N1
642650
> {
@@ -669,7 +677,7 @@ A *using_static_directive* specifically does not import extension methods direct
669677
670678
> *Example*:
671679
>
672-
> <!-- Example: {template:"standalone-lib", name:"UsingStaticDirectives2", expectedErrors:["CS0103"]} -->
680+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingStaticDirectives2", expectedErrors:["CS0103"]} -->
673681
> ```csharp
674682
> namespace N1
675683
> {
@@ -703,16 +711,16 @@ A *using_static_directive* only imports members and types declared directly in t
703711
704712
> *Example*:
705713
>
706-
> <!-- NeedsReviewExample: {template:"standalone-lib", name:"UsingStaticDirectives3", replaceEllipsis:true, expectedOutput:["x", "x", "x"], expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
714+
> <!-- Example: {template:"standalone-lib-without-using", name:"UsingStaticDirectives3", expectedErrors:["CS0103"]} -->
707715
> ```csharp
708716
> namespace N1
709717
> {
710-
> static class A
718+
> class A
711719
> {
712720
> public static void M(string s){}
713721
> }
714722
>
715-
> static class B : A
723+
> class B : A
716724
> {
717725
> public static void M2(string s){}
718726
> }
@@ -819,7 +827,7 @@ Using this notation, the meaning of a *qualified_alias_member* is determined as
819827

820828
> *Example*: In the code:
821829
>
822-
> <!-- Example: {template:"standalone-lib", name:"QualifiedAliasMember1"} -->
830+
> <!-- Example: {template:"standalone-lib-without-using", name:"QualifiedAliasMember1"} -->
823831
> ```csharp
824832
> using S = System.Net.Sockets;
825833
>
@@ -848,7 +856,7 @@ Using this notation, the meaning of a *qualified_alias_member* is determined as
848856
<!-- markdownlint-enable MD028 -->
849857
> *Note*: The identifier `global` has special meaning only when used as the left-hand identifier of a *qualified_alias_name*. It is not a keyword and it is not itself an alias; it is a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)). In the code:
850858
>
851-
> <!-- Example: {template:"standalone-lib", name:"QualifiedAliasMember2", expectedErrors:["CS0246"], ignoredWarnings:["CS0169"]} -->
859+
> <!-- Example: {template:"standalone-lib-without-using", name:"QualifiedAliasMember2", expectedErrors:["CS0246"], ignoredWarnings:["CS0169"]} -->
852860
> ```csharp
853861
> class A { }
854862
>
@@ -863,7 +871,7 @@ Using this notation, the meaning of a *qualified_alias_member* is determined as
863871
>
864872
> Using `global` as the left-hand identifier of a *qualified_alias_member* always causes a lookup in the `global` namespace, even if there is a using alias named `global`. In the code:
865873
>
866-
> <!-- IncompleteExample: {template:"standalone-lib", name:"QualifiedAliasMember3", expectedErrors:["x","x"], expectedWarnings:["CS0440"], ignoredWarnings:["CS0169"]} -->
874+
> <!-- Example: {template:"standalone-lib-without-using", name:"QualifiedAliasMember3", additionalFiles:["MyGlobalTypes.cs"], ignoredWarnings:["CS0169","CS0440"]} -->
867875
> ```csharp
868876
> using global = MyGlobalTypes;
869877
>
@@ -886,7 +894,7 @@ Each compilation unit and namespace body has a separate declaration space for ex
886894
887895
> *Example*: In the following:
888896
>
889-
> <!-- Example: {template:"standalone-lib", name:"UniquenessOfAliases", expectedErrors:["CS0576"], ignoredWarnings:["CS0169"]} -->
897+
> <!-- Example: {template:"standalone-lib-without-using", name:"UniquenessOfAliases", expectedErrors:["CS0576"], ignoredWarnings:["CS0169"]} -->
890898
> ```csharp
891899
> namespace N
892900
> {

0 commit comments

Comments
 (0)