CodeNamespace 類別

定義

表示命名空間 (Namespace) 宣告。

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
繼承
CodeNamespace
屬性

範例

下列範例程式代碼示範如何使用 CodeNamespace 來宣告命名空間。

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 可用來表示命名空間宣告。

屬性 Name 會指定命名空間的名稱。 屬性 Imports 包含命名空間的命名空間彙入指示詞。 屬性 Types 包含命名空間的類型宣告。 屬性 Comments 包含套用在命名空間層級的批註。

在某些語言中,命名空間可以做為類型宣告的容器;如果類型名稱之間沒有衝突,則相同命名空間中的所有類型都可以存取,而不需使用完整型別參考。

注意

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

建構函式

CodeNamespace()

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

CodeNamespace(String)

使用指定的名稱來初始化 CodeNamespace 類別的新執行個體。

屬性

Comments

取得命名空間的註解。

Imports

取得命名空間所用的命名空間 Import 指示詞集合。

Name

取得或設定命名空間的名稱。

Types

取得命名空間所包含的型別集合。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

事件

PopulateComments

第一次存取 Comments 集合時,將引發的事件。

PopulateImports

第一次存取 Imports 集合時,將引發的事件。

PopulateTypes

第一次存取 Types 集合時,將引發的事件。

適用於