CodeNamespace CodeNamespace CodeNamespace CodeNamespace Class

Definition

Represents a namespace declaration.

public ref class CodeNamespace : System::CodeDom::CodeObject
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeNamespace : System.CodeDom.CodeObject
type CodeNamespace = class
    inherit CodeObject
Public Class CodeNamespace
Inherits CodeObject
Inheritance
CodeNamespaceCodeNamespaceCodeNamespaceCodeNamespace
Attributes

Examples

The following example code demonstrates use of a CodeNamespace to declare a namespace.

CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;
CodeNamespace^ namespace1 = gcnew CodeNamespace( "TestNamespace" );
compileUnit->Namespaces->Add( namespace1 );

// A C# code generator produces the following source code for the preceeding example code:
//     namespace TestNamespace {    
//     }
CodeCompileUnit compileUnit = new CodeCompileUnit();
CodeNamespace namespace1 = new CodeNamespace("TestNamespace");
compileUnit.Namespaces.Add( namespace1 );

// A C# code generator produces the following source code for the preceeding example code:

//     namespace TestNamespace {    
//     }

Dim compileUnit As New CodeCompileUnit()
Dim namespace1 As New CodeNamespace("TestNamespace")
compileUnit.Namespaces.Add(namespace1)

' A Visual Basic code generator produces the following source code for the preceeding example code:

'     Namespace TestNamespace
'     End Namespace

Remarks

CodeNamespace can be used to represent a namespace declaration.

The Name property specifies the name of the namespace. The Imports property contains the namespace import directives for the namespace. The Types property contains the type declarations for the namespace. The Comments property contains the comments that apply at the namespace level.

In some languages, a namespace can function as a container for type declarations; all types in the same namespace are accessible without using fully-qualified type references, if the there is no conflict between type names.

Note

Use fully qualified type references to avoid potential ambiguity.

Constructors

CodeNamespace() CodeNamespace() CodeNamespace() CodeNamespace()

Initializes a new instance of the CodeNamespace class.

CodeNamespace(String) CodeNamespace(String) CodeNamespace(String) CodeNamespace(String)

Initializes a new instance of the CodeNamespace class using the specified name.

Properties

Comments Comments Comments Comments

Gets the comments for the namespace.

Imports Imports Imports Imports

Gets the collection of namespace import directives used by the namespace.

Name Name Name Name

Gets or sets the name of the namespace.

Types Types Types Types

Gets the collection of types that the namespace contains.

UserData UserData UserData UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Events

PopulateComments PopulateComments PopulateComments PopulateComments

An event that will be raised the first time the Comments collection is accessed.

PopulateImports PopulateImports PopulateImports PopulateImports

An event that will be raised the first time the Imports collection is accessed.

PopulateTypes PopulateTypes PopulateTypes PopulateTypes

An event that will be raised the first time the Types collection is accessed.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to