CodeNamespaceImport 類別

定義

表示命名空間匯入指示詞,其指示所要使用的命名空間。

public ref class CodeNamespaceImport : System::CodeDom::CodeObject
public class CodeNamespaceImport : System.CodeDom.CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeNamespaceImport : System.CodeDom.CodeObject
type CodeNamespaceImport = class
    inherit CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeNamespaceImport = class
    inherit CodeObject
Public Class CodeNamespaceImport
Inherits CodeObject
繼承
CodeNamespaceImport
屬性

範例

下列範例程式代碼示範如何使用 CodeNamespaceImport 來匯入 CodeNamespaceImport 命名空間:

// Declares a compile unit to contain a namespace.
CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;

// Declares a namespace named TestNamespace.
CodeNamespace^ testNamespace = gcnew 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 = gcnew 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;
//
//  }
// 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;
//
//  }
' 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
'
'            '
'Namespace TestNamespace
'End Namespace

備註

CodeNamespaceImport 可用來表示命名空間彙入指示詞。

在大部分語言中,命名空間彙入指示詞會導致匯入命名空間內類型的可見度,指向參考所匯入命名空間中類型的程序代碼。

注意

使用完整型別參考來避免潛在的模棱兩可。

建構函式

CodeNamespaceImport()

初始化 CodeNamespaceImport 類別的新執行個體。

CodeNamespaceImport(String)

使用要匯入的指定命名空間來初始化 CodeNamespaceImport 類別的新執行個體。

屬性

LinePragma

取得或設定發生陳述式 (Statement) 的行和檔案。

Namespace

取得或設定要匯入的命名空間。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱