Merge pull request #3716 from vargaz/unbox-stobj-null
[mono.git] / mcs / class / referencesource / System / compmod / system / codedom / CodeNamespace.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CodeNamespace.cs" company="Microsoft">
3 // 
4 // <OWNER>[....]</OWNER>
5 //     Copyright (c) Microsoft Corporation.  All rights reserved.
6 // </copyright>                                                                
7 //------------------------------------------------------------------------------
8
9 namespace System.CodeDom {
10
11     using System.Diagnostics;
12     using System;
13     using Microsoft.Win32;
14     using System.Collections;
15     using System.Runtime.Serialization;
16     using System.Runtime.InteropServices;
17
18     /// <devdoc>
19     ///    <para>
20     ///       Represents a
21     ///       namespace declaration.
22     ///    </para>
23     /// </devdoc>
24     [
25         ClassInterface(ClassInterfaceType.AutoDispatch),
26         ComVisible(true),
27         Serializable,
28     ]
29     public class CodeNamespace: CodeObject {
30         private string name;
31         private CodeNamespaceImportCollection imports = new CodeNamespaceImportCollection();
32         private CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
33         private CodeTypeDeclarationCollection classes = new CodeTypeDeclarationCollection();
34 #if CODEDOM_NESTED_NAMESPACES
35         private CodeNamespaceCollection namespaces = new CodeNamespaceCollection();
36 #endif
37         
38         private int  populated = 0x0;
39         private const int ImportsCollection = 0x1;
40         private const int CommentsCollection = 0x2;
41         private const int TypesCollection = 0x4;
42         
43 #if CODEDOM_NESTED_NAMESPACES
44         private const int NamespacesCollection = 0x8;
45 #endif
46         
47         
48        
49         /// <devdoc>
50         ///    <para>
51         ///       An event that will be fired the first time the Comments Collection is accessed.  
52         ///    </para>
53         /// </devdoc>
54         public event EventHandler PopulateComments;
55         
56          /// <devdoc>
57         ///    <para>
58         ///       An event that will be fired the first time the Imports Collection is accessed.  
59         ///    </para>
60         /// </devdoc>
61         public event EventHandler PopulateImports;
62
63 #if CODEDOM_NESTED_NAMESPACES
64          /// <devdoc>
65         ///    <para>
66         ///       An event that will be fired the first time the Namespaces Collection is accessed.  
67         ///    </para>
68         /// </devdoc>
69         public event EventHandler PopulateNamespaces;
70 #endif
71         
72         
73         /// <devdoc>
74         ///    <para>
75         ///       An event that will be fired the first time the Types Collection is accessed.  
76         ///    </para>
77         /// </devdoc>
78         public event EventHandler PopulateTypes;
79
80         /// <devdoc>
81         ///    <para>
82         ///       Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/>.
83         ///    </para>
84         /// </devdoc>
85         public CodeNamespace() {
86         }
87
88         /// <devdoc>
89         ///    <para>
90         ///       Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/> using the specified name.
91         ///    </para>
92         /// </devdoc>
93         public CodeNamespace(string name) {
94             Name = name;
95         }
96
97         private CodeNamespace(SerializationInfo info, StreamingContext context) {
98         }
99
100         /// <devdoc>
101         ///    <para>
102         ///       Gets or sets the collection of classes.
103         ///    </para>
104         /// </devdoc>
105         public CodeTypeDeclarationCollection Types {
106             get {
107                 if (0 == (populated & TypesCollection)) {
108                     populated |= TypesCollection;
109                     if (PopulateTypes != null) PopulateTypes(this, EventArgs.Empty);
110                 }
111                 return classes;
112             }
113         }
114
115         /// <devdoc>
116         ///    <para>
117         ///       Gets or sets the collection of namespace imports used by the represented
118         ///       namespace.
119         ///    </para>
120         /// </devdoc>
121         public CodeNamespaceImportCollection Imports {
122             get {
123                 if (0 == (populated & ImportsCollection)) {
124                     populated |= ImportsCollection;
125                     if (PopulateImports != null) PopulateImports(this, EventArgs.Empty);
126                 }
127                 return imports;
128             }
129         }
130
131         /// <devdoc>
132         ///    <para>
133         ///       Gets or sets the name of the namespace.
134         ///    </para>
135         /// </devdoc>
136         public string Name {
137             get {
138                 return (name == null) ? string.Empty : name;
139             }
140             set {
141                 name = value;
142             }
143         }
144         
145         
146 #if CODEDOM_NESTED_NAMESPACES
147         
148         /// <devdoc>
149         ///    <para>
150         ///       Gets or sets the collection of Namespaces.
151         ///    </para>
152         /// </devdoc>
153         public CodeNamespaceCollection Namespaces {
154             get {
155                 if (0 == (populated & NamespacesCollection)) {
156                     populated |= NamespacesCollection;
157                     if (PopulateNamespaces != null) PopulateNamespaces(this, EventArgs.Empty);
158                 }
159                 return namespaces;
160             }
161         }
162
163 #endif
164
165         /// <devdoc>
166         ///    <para>
167         ///       Gets or sets the member comment collection members.
168         ///    </para>
169         /// </devdoc>
170         public CodeCommentStatementCollection Comments {
171             get {
172                 if (0 == (populated & CommentsCollection)) {
173                     populated |= CommentsCollection;
174                     if (PopulateComments != null) PopulateComments(this, EventArgs.Empty);
175                 }
176                 return comments;
177             }
178         }
179     }
180 }