CodeNamespace 類別

定義

表示命名空間 (Namespace) 宣告。Represents a namespace declaration.

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

範例

下列範例程式碼示範CodeNamespace如何使用來宣告命名空間。The following example code demonstrates use of a CodeNamespace to declare a namespace.

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可以用來表示命名空間宣告。CodeNamespace can be used to represent a namespace declaration.

Name屬性會指定命名空間的名稱。The Name property specifies the name of the namespace. Imports屬性包含命名空間的命名空間匯入指示詞。The Imports property contains the namespace import directives for the namespace. Types屬性包含命名空間的類型宣告。The Types property contains the type declarations for the namespace. Comments屬性包含適用于命名空間層級的批註。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.

注意

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

建構函式

CodeNamespace()

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

CodeNamespace(String)

使用指定的名稱來初始化 CodeNamespace 類別的新執行個體。Initializes a new instance of the CodeNamespace class using the specified name.

屬性

Comments

取得命名空間的註解。Gets the comments for the namespace.

Imports

取得命名空間所用的命名空間 Import 指示詞集合。Gets the collection of namespace import directives used by the namespace.

Name

取得或設定命名空間的名稱。Gets or sets the name of the namespace.

Types

取得命名空間所包含的型別集合。Gets the collection of types that the namespace contains.

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

PopulateComments

第一次存取 Comments 集合時,將引發的事件。An event that will be raised the first time the Comments collection is accessed.

PopulateImports

第一次存取 Imports 集合時,將引發的事件。An event that will be raised the first time the Imports collection is accessed.

PopulateTypes

第一次存取 Types 集合時,將引發的事件。An event that will be raised the first time the Types collection is accessed.

適用於