1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Runtime.Serialization; 6 7 namespace System.CodeDom 8 { 9 [Serializable] 10 public class CodeNamespace : CodeObject 11 { 12 private string _name; 13 private readonly CodeNamespaceImportCollection _imports = new CodeNamespaceImportCollection(); 14 private readonly CodeCommentStatementCollection _comments = new CodeCommentStatementCollection(); 15 private readonly CodeTypeDeclarationCollection _classes = new CodeTypeDeclarationCollection(); 16 17 private int _populated = 0x0; 18 private const int ImportsCollection = 0x1; 19 private const int CommentsCollection = 0x2; 20 private const int TypesCollection = 0x4; 21 22 public event EventHandler PopulateComments; 23 public event EventHandler PopulateImports; 24 public event EventHandler PopulateTypes; 25 CodeNamespace()26 public CodeNamespace() { } 27 CodeNamespace(string name)28 public CodeNamespace(string name) 29 { 30 Name = name; 31 } 32 33 public CodeTypeDeclarationCollection Types 34 { 35 get 36 { 37 if (0 == (_populated & TypesCollection)) 38 { 39 _populated |= TypesCollection; 40 PopulateTypes?.Invoke(this, EventArgs.Empty); 41 } 42 return _classes; 43 } 44 } 45 46 public CodeNamespaceImportCollection Imports 47 { 48 get 49 { 50 if (0 == (_populated & ImportsCollection)) 51 { 52 _populated |= ImportsCollection; 53 PopulateImports?.Invoke(this, EventArgs.Empty); 54 } 55 return _imports; 56 } 57 } 58 59 public string Name 60 { 61 get { return _name ?? string.Empty; } 62 set { _name = value; } 63 } 64 65 public CodeCommentStatementCollection Comments 66 { 67 get 68 { 69 if (0 == (_populated & CommentsCollection)) 70 { 71 _populated |= CommentsCollection; 72 PopulateComments?.Invoke(this, EventArgs.Empty); 73 } 74 return _comments; 75 } 76 } 77 } 78 } 79