The Labs \ Source Viewer \ SSCLI \ System.CodeDom \ CodeNamespace

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CodeNamespace.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.CodeDom
  16. {
  17.    
  18.     using System.Diagnostics;
  19.     using System;
  20.     using Microsoft.Win32;
  21.     using System.Collections;
  22.     using System.Runtime.Serialization;
  23.     using System.Runtime.InteropServices;
  24.    
  25.     /// <devdoc>
  26.     /// <para>
  27.     /// Represents a
  28.     /// namespace declaration.
  29.     /// </para>
  30.     /// </devdoc>
  31.     [ClassInterface(ClassInterfaceType.AutoDispatch), ComVisible(true), Serializable()]
  32.     public class CodeNamespace : CodeObject
  33.     {
  34.         private string name;
  35.         private CodeNamespaceImportCollection imports = new CodeNamespaceImportCollection();
  36.         private CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
  37.         private CodeTypeDeclarationCollection classes = new CodeTypeDeclarationCollection();
  38.         private CodeNamespaceCollection namespaces = new CodeNamespaceCollection();
  39.        
  40.         private int populated = 0;
  41.         private const int ImportsCollection = 1;
  42.         private const int CommentsCollection = 2;
  43.         private const int TypesCollection = 4;
  44.        
  45.        
  46.        
  47.        
  48.         /// <devdoc>
  49.         /// <para>
  50.         /// An event that will be fired the first time the Comments Collection is accessed.
  51.         /// </para>
  52.         /// </devdoc>
  53.         public event EventHandler PopulateComments;
  54.        
  55.         /// <devdoc>
  56.         /// <para>
  57.         /// An event that will be fired the first time the Imports Collection is accessed.
  58.         /// </para>
  59.         /// </devdoc>
  60.         public event EventHandler PopulateImports;
  61.        
  62.        
  63.        
  64.         /// <devdoc>
  65.         /// <para>
  66.         /// An event that will be fired the first time the Types Collection is accessed.
  67.         /// </para>
  68.         /// </devdoc>
  69.         public event EventHandler PopulateTypes;
  70.        
  71.         /// <devdoc>
  72.         /// <para>
  73.         /// Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/>.
  74.         /// </para>
  75.         /// </devdoc>
  76.         public CodeNamespace()
  77.         {
  78.         }
  79.        
  80.         /// <devdoc>
  81.         /// <para>
  82.         /// Initializes a new instance of <see cref='System.CodeDom.CodeNamespace'/> using the specified name.
  83.         /// </para>
  84.         /// </devdoc>
  85.         public CodeNamespace(string name)
  86.         {
  87.             Name = name;
  88.         }
  89.        
  90.         private CodeNamespace(SerializationInfo info, StreamingContext context)
  91.         {
  92.         }
  93.        
  94.         /// <devdoc>
  95.         /// <para>
  96.         /// Gets or sets the collection of classes.
  97.         /// </para>
  98.         /// </devdoc>
  99.         public CodeTypeDeclarationCollection Types {
  100.             get {
  101.                 if (0 == (populated & TypesCollection)) {
  102.                     populated |= TypesCollection;
  103.                     if (PopulateTypes != null)
  104.                         PopulateTypes(this, EventArgs.Empty);
  105.                 }
  106.                 return classes;
  107.             }
  108.         }
  109.        
  110.         /// <devdoc>
  111.         /// <para>
  112.         /// Gets or sets the collection of namespace imports used by the represented
  113.         /// namespace.
  114.         /// </para>
  115.         /// </devdoc>
  116.         public CodeNamespaceImportCollection Imports {
  117.             get {
  118.                 if (0 == (populated & ImportsCollection)) {
  119.                     populated |= ImportsCollection;
  120.                     if (PopulateImports != null)
  121.                         PopulateImports(this, EventArgs.Empty);
  122.                 }
  123.                 return imports;
  124.             }
  125.         }
  126.        
  127.         /// <devdoc>
  128.         /// <para>
  129.         /// Gets or sets the name of the namespace.
  130.         /// </para>
  131.         /// </devdoc>
  132.         public string Name {
  133.             get { return (name == null) ? string.Empty : name; }
  134.             set { name = value; }
  135.         }
  136.        
  137.        
  138.        
  139.         /// <devdoc>
  140.         /// <para>
  141.         /// Gets or sets the member comment collection members.
  142.         /// </para>
  143.         /// </devdoc>
  144.         public CodeCommentStatementCollection Comments {
  145.             get {
  146.                 if (0 == (populated & CommentsCollection)) {
  147.                     populated |= CommentsCollection;
  148.                     if (PopulateComments != null)
  149.                         PopulateComments(this, EventArgs.Empty);
  150.                 }
  151.                 return comments;
  152.             }
  153.         }
  154.     }
  155. }

Developer Fusion