Export (0) Print
Expand All

CodeNamespaceImport Class

Represents a namespace import directive that indicates a namespace to use.

For a list of all members of this type, see CodeNamespaceImport Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeNamespaceImport

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeNamespaceImport
   Inherits CodeObject
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeNamespaceImport : CodeObject
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeNamespaceImport : public CodeObject
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeNamespaceImport 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

CodeNamespaceImport can be used to represent a namespace import directive.

In most languages, a namespace import directive causes visibility of the types within the imported namespaces to code that references types in the imported namespaces.

Note   Use fully qualified type references to avoid potential ambiguity.

Example

[Visual Basic, C#, C++] The following example code demonstrates use of a CodeNamespaceImport to import the CodeNamespaceImport namespace:

[Visual Basic] 
' Declares a compile unit to contain a namespace.
Dim compileUnit As New CodeCompileUnit()

' Declares a namespace named TestNamespace.
Dim testNamespace As New CodeNamespace("TestNamespace")
' Adds the namespace to the namespace collection of the compile unit.
compileUnit.Namespaces.Add(testNamespace)

' Declares a namespace import of the System namespace.
Dim import1 As New CodeNamespaceImport("System")
' Adds the namespace import to the namespace imports collection of the namespace.
testNamespace.Imports.Add(import1)

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

'Option Strict Off
'Option Explicit On
'
'Imports System
'
'Namespace TestNamespace
'End Namespace


[C#] 
// Declares a compile unit to contain a namespace.
CodeCompileUnit compileUnit = new CodeCompileUnit();

// Declares a namespace named TestNamespace.
CodeNamespace testNamespace = new CodeNamespace("TestNamespace");
// Adds the namespace to the namespace collection of the compile unit.
compileUnit.Namespaces.Add(testNamespace);

// Declares a namespace import of the System namespace.
CodeNamespaceImport import1 = new CodeNamespaceImport("System");
// Adds the namespace import to the namespace imports collection of the namespace.
testNamespace.Imports.Add(import1);

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

//    namespace TestNamespace {        
//        using System;
//
//  }


[C++] 
// Declares a compile unit to contain a namespace.
CodeCompileUnit* compileUnit = new CodeCompileUnit();

// Declares a namespace named TestNamespace.
CodeNamespace* testNamespace = new CodeNamespace(S"TestNamespace");
// Adds the namespace to the namespace collection of the compile unit.
compileUnit->Namespaces->Add(testNamespace);

// Declares a namespace import of the System namespace.
CodeNamespaceImport* import1 = new CodeNamespaceImport(S"System");
// Adds the namespace import to the namespace imports collection of the namespace.
testNamespace->Imports->Add(import1);

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

//    namespace TestNamespace {        
//        using System;
//
//  }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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)

See Also

CodeNamespaceImport Members | System.CodeDom Namespace | CodeNamespaceImportCollection

Show:
© 2015 Microsoft