disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 16.3.2.xml
blob49a9849c3b0761318c0d361c36390f6daac26ab6
1 <?xml version="1.0"?>
2 <clause number="16.3.2" title="Using namespace directives">
3   <paragraph>A <non_terminal where="16.3.2">using-namespace-directive</non_terminal> imports the types contained in a namespace into the immediately enclosing compilation unit or namespace body, enabling the identifier of each type to be used without qualification. <grammar_production><name><non_terminal where="16.3.2">using-namespace-directive</non_terminal></name> : <rhs><keyword>using</keyword><non_terminal where="10.8">namespace-name</non_terminal><terminal>;</terminal></rhs></grammar_production></paragraph>
4   <paragraph>Within member declarations in a compilation unit or namespace body that contains a  <non_terminal where="16.3.2">using-namespace-directive</non_terminal>, the types contained in the given namespace can be referenced directly. <example>[Example: For example: <code_example><![CDATA[
5 namespace N1.N2  
6 {  
7    class A {}  
8 }  
9 namespace N3  
10 {  
11    using N1.N2;  
12    class B: A {}  
13 }  
14 ]]></code_example></example></paragraph>
15   <paragraph>
16     <example>Above, within member declarations in the N3 namespace, the type members of N1.N2 are directly available, and thus class N3.B derives from class N1.N2.A. end example]</example>
17   </paragraph>
18   <paragraph>A <non_terminal where="16.3.2">using-namespace-directive</non_terminal> imports the types contained in the given namespace, but specifically does not import nested namespaces. <example>[Example: In the example <code_example><![CDATA[
19 namespace N1.N2  
20 {  
21    class A {}  
22 }  
23 namespace N3  
24 {  
25    using N1;  
26    class B: N2.A {}    // Error, N2 unknown  
27 }  
28 ]]></code_example>the <non_terminal where="16.3.2">using-namespace-directive</non_terminal> imports the types contained in N1, but not the namespaces nested in N1. Thus, the reference to N2.A in the declaration of B results in a compile-time error because no members named N2 are in scope. end example]</example> </paragraph>
29   <paragraph>Unlike a <non_terminal where="16.3.1">using-alias-directive</non_terminal>, a <non_terminal where="16.3.2">using-namespace-directive</non_terminal> may import types whose identifiers are already defined within the enclosing compilation unit or namespace body. In effect, names imported by a  <non_terminal where="16.3.2">using-namespace-directive</non_terminal> are hidden by similarly named members in the enclosing compilation unit or namespace body. <example>[Example: For example: <code_example><![CDATA[
30 namespace N1.N2  
31 {  
32    class A {}  
33    class B {}  
34 }  
35 namespace N3  
36 {  
37    using N1.N2;  
38    class A {}  
39 }  
40 ]]></code_example></example></paragraph>
41   <paragraph>
42     <example>Here, within member declarations in the N3 namespace, A refers to N3.A rather than N1.N2.A. end example]</example>
43   </paragraph>
44   <paragraph>When more than one namespace imported by <non_terminal where="16.3.2">using-namespace-directive</non_terminal>s in the same compilation unit or namespace body contain types by the same name, references to that name are considered ambiguous. </paragraph>
45   <paragraph><example>[Example: In the example <code_example><![CDATA[
46 namespace N1  
47 {  
48    class A {}  
49 }  
50 namespace N2  
51 {  
52    class A {}  
53 }  
54 namespace N3  
55 {  
56    using N1;  
57    using N2;  
58    class B: A {}     // Error, A is ambiguous  
59 }  
60 ]]></code_example>both N1 and N2 contain a member A, and because N3 imports both, referencing A in N3 is a compile-time error. end example]</example> In this situation, the conflict can be resolved either through qualification of references to A, or by introducing a <non_terminal where="16.3.1">using-alias-directive</non_terminal> that picks a particular A. <example>[Example: For example: <code_example><![CDATA[
61 namespace N3  
62 {  
63    using N1;  
64    using N2;  
65    using A = N1.A;  
66    class B: A {}     // A means N1.A  
67 }  
68 ]]></code_example>end example]</example></paragraph>
69   <paragraph>Like a <non_terminal where="16.3.1">using-alias-directive</non_terminal>, a <non_terminal where="16.3.2">using-namespace-directive</non_terminal> does not contribute any new members to the underlying declaration space of the compilation unit or namespace, but, rather, affects only the compilation unit or namespace body in which it appears. </paragraph>
70   <paragraph>The <non_terminal where="10.8">namespace-name</non_terminal> referenced by a <non_terminal where="16.3.2">using-namespace-directive</non_terminal> is resolved in the same way as the <non_terminal where="10.8">namespace-or-type-name</non_terminal> referenced by a <non_terminal where="16.3.1">using-alias-directive</non_terminal>. Thus, <non_terminal where="16.3.2">using-namespace-directive</non_terminal>s in the same compilation unit or namespace body do not affect each other and can be written in any order. </paragraph>
71 </clause>