CodeNamespace Class
Represents a namespace declaration.
For a list of all members of this type, see CodeNamespace Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeNamespace
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeNamespace Inherits CodeObject [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeNamespace : CodeObject [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeNamespace : public CodeObject [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeNamespace extends CodeObject
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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 System.CodeDom.CodeNamespace.Namespaces property contains any nested namespaces. 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.
Example
[Visual Basic, C#, C++] The following example code demonstrates use of a CodeNamespace to declare a namespace.
[Visual Basic] 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 [C#] 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 { // } [C++] CodeCompileUnit* compileUnit = new CodeCompileUnit(); CodeNamespace* namespace1 = new CodeNamespace(S"TestNamespace"); compileUnit->Namespaces->Add( namespace1 ); // A C# code generator produces the following source code for the preceeding example code: // namespace TestNamespace { // }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)