CodeNamespaceImport CodeNamespaceImport CodeNamespaceImport CodeNamespaceImport Class

定義

表示命名空間匯入指示詞,其指示所要使用的命名空間。Represents a namespace import directive that indicates a namespace to use.

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

範例

下列範例程式碼示範CodeNamespaceImport如何使用來匯CodeNamespaceImport入命名空間:The following example code demonstrates use of a CodeNamespaceImport to import the CodeNamespaceImport namespace:

// 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 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.

注意

請使用完整型別參考來避免潛在的不明確。Use fully qualified type references to avoid potential ambiguity.

建構函式

CodeNamespaceImport() CodeNamespaceImport() CodeNamespaceImport() CodeNamespaceImport()

初始化 CodeNamespaceImport 類別的新執行個體。Initializes a new instance of the CodeNamespaceImport class.

CodeNamespaceImport(String) CodeNamespaceImport(String) CodeNamespaceImport(String) CodeNamespaceImport(String)

使用要匯入的指定命名空間來初始化 CodeNamespaceImport 類別的新執行個體。Initializes a new instance of the CodeNamespaceImport class using the specified namespace to import.

屬性

LinePragma LinePragma LinePragma LinePragma

取得或設定發生陳述式 (Statement) 的行和檔案。Gets or sets the line and file the statement occurs on.

Namespace Namespace Namespace Namespace

取得或設定要匯入的命名空間。Gets or sets the namespace to import.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

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()

取得目前執行個體的 TypeGets the Type of the current instance.

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

建立目前 Object 的淺層複本 (Shallow Copy)。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)

適用於

另請參閱