1 //------------------------------------------------------------------------------
2 // <copyright file="CodeNamespace.cs" company="Microsoft">
4 // <OWNER>[....]</OWNER>
5 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //------------------------------------------------------------------------------
9 namespace System.CodeDom {
11 using System.Diagnostics;
13 using Microsoft.Win32;
14 using System.Collections;
15 using System.Runtime.Serialization;
16 using System.Runtime.InteropServices;
21 /// namespace declaration.
25 ClassInterface(ClassInterfaceType.AutoDispatch),
29 public class CodeNamespace: CodeObject {
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();
38 private int populated = 0x0;
39 private const int ImportsCollection = 0x1;
40 private const int CommentsCollection = 0x2;
41 private const int TypesCollection = 0x4;
43 #if CODEDOM_NESTED_NAMESPACES
44 private const int NamespacesCollection = 0x8;
51 /// An event that will be fired the first time the Comments Collection is accessed.
54 public event EventHandler PopulateComments;
58 /// An event that will be fired the first time the Imports Collection is accessed.
61 public event EventHandler PopulateImports;
63 #if CODEDOM_NESTED_NAMESPACES
66 /// An event that will be fired the first time the Namespaces Collection is accessed.
69 public event EventHandler PopulateNamespaces;
75 /// An event that will be fired the first time the Types Collection is accessed.
78 public event EventHandler PopulateTypes;
82 /// Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/>.
85 public CodeNamespace() {
90 /// Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/> using the specified name.
93 public CodeNamespace(string name) {
97 private CodeNamespace(SerializationInfo info, StreamingContext context) {
102 /// Gets or sets the collection of classes.
105 public CodeTypeDeclarationCollection Types {
107 if (0 == (populated & TypesCollection)) {
108 populated |= TypesCollection;
109 if (PopulateTypes != null) PopulateTypes(this, EventArgs.Empty);
117 /// Gets or sets the collection of namespace imports used by the represented
121 public CodeNamespaceImportCollection Imports {
123 if (0 == (populated & ImportsCollection)) {
124 populated |= ImportsCollection;
125 if (PopulateImports != null) PopulateImports(this, EventArgs.Empty);
133 /// Gets or sets the name of the namespace.
138 return (name == null) ? string.Empty : name;
146 #if CODEDOM_NESTED_NAMESPACES
150 /// Gets or sets the collection of Namespaces.
153 public CodeNamespaceCollection Namespaces {
155 if (0 == (populated & NamespacesCollection)) {
156 populated |= NamespacesCollection;
157 if (PopulateNamespaces != null) PopulateNamespaces(this, EventArgs.Empty);
167 /// Gets or sets the member comment collection members.
170 public CodeCommentStatementCollection Comments {
172 if (0 == (populated & CommentsCollection)) {
173 populated |= CommentsCollection;
174 if (PopulateComments != null) PopulateComments(this, EventArgs.Empty);