CodeNamespace Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a namespace declaration.
public ref class CodeNamespace : System::CodeDom::CodeObject
public class CodeNamespace : System.CodeDom.CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeNamespace : System.CodeDom.CodeObject
type CodeNamespace = class
inherit CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeNamespace = class
inherit CodeObject
Public Class CodeNamespace
Inherits CodeObject
- Inheritance
- Attributes
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
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 there is no conflict between type names.
Note
Use fully qualified type references to avoid potential ambiguity.
Code |
Initializes a new instance of the CodeNamespace class. |
Code |
Initializes a new instance of the CodeNamespace class using the specified name. |
Comments |
Gets the comments for the namespace. |
Imports |
Gets the collection of namespace import directives used by the namespace. |
Name |
Gets or sets the name of the namespace. |
Types |
Gets the collection of types that the namespace contains. |
User |
Gets the user-definable data for the current object. (Inherited from CodeObject) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Populate |
An event that will be raised the first time the Comments collection is accessed. |
Populate |
An event that will be raised the first time the Imports collection is accessed. |
Populate |
An event that will be raised the first time the Types collection is accessed. |
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: