CodeTypeDeclaration 類別

定義

表示類別、結構、介面或列舉型別的型別宣告。

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

範例

此範例示範如何使用 CodeTypeDeclaration 來宣告型別。

// Creates a new type declaration.

// name parameter indicates the name of the type.
CodeTypeDeclaration^ newType = gcnew CodeTypeDeclaration( "TestType" );

// Sets the member attributes for the type to private.
newType->Attributes = MemberAttributes::Private;

// Sets a base class which the type inherits from.
newType->BaseTypes->Add( "BaseType" );

// A C# code generator produces the following source code for the preceeding example code:
// class TestType : BaseType
// {
// }
// Creates a new type declaration.
CodeTypeDeclaration newType = new CodeTypeDeclaration(
    // name parameter indicates the name of the type.
    "TestType");
// Sets the member attributes for the type to private.
newType.Attributes = MemberAttributes.Private;
// Sets a base class which the type inherits from.
newType.BaseTypes.Add( "BaseType" );

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

// class TestType : BaseType
// {
// }
' Creates a new type declaration.
Dim newType As New CodeTypeDeclaration("TestType")
   ' name parameter indicates the name of the type.
   ' Sets the member attributes for the type to private.
   newType.Attributes = MemberAttributes.Private
   ' Sets a base class which the type inherits from.
   newType.BaseTypes.Add("BaseType")

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

' Class TestType
'    Inherits BaseType
' End Class

備註

CodeTypeDeclaration 可用來表示宣告類別、結構、介面或列舉的程序代碼。 CodeTypeDeclaration 可用來宣告另一個類型內巢狀的類型。

屬性 BaseTypes 會指定所宣告型別的基底類型或基底類型。 屬性 Members 包含類型成員,可包含方法、欄位、屬性、批註和其他類型。 屬性 TypeAttributesTypeAttributes 指出型別宣告的值,這表示型別的類型類別目錄。 IsClassIsStructIsEnumIsInterface 方法會分別指出類型是否為類別、結構、列舉或介面類型。

注意

某些程式設計語言僅支持參考型別或類別的宣告。 若要檢查語言特定的 CodeDOM 程式代碼產生器,以取得宣告介面、列舉或實值類型的支援,請呼叫 Supports 方法來測試適當的 GeneratorSupport 旗標。 DeclareInterfaces 表示介面的支援、 DeclareEnums 表示列舉的支援,以及 DeclareValueTypes 指出支持實值型別,例如結構。

您可以在一個完整宣告中建置類別或結構實作,或將實作分散到多個宣告。 屬性 IsPartial 會指出類型宣告已完成還是部分。 並非所有程式代碼產生器都支援部分類型宣告,因此您應該使用旗PartialTypes標呼叫 Supports 方法來測試此支援。

建構函式

CodeTypeDeclaration()

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

CodeTypeDeclaration(String)

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

屬性

Attributes

取得或設定成員的屬性 (Attribute)。

(繼承來源 CodeTypeMember)
BaseTypes

取得型別的基底型別。

Comments

取得型別成員的註解集合。

(繼承來源 CodeTypeMember)
CustomAttributes

取得或設定成員的自訂屬性。

(繼承來源 CodeTypeMember)
EndDirectives

取得成員的結尾指示詞。

(繼承來源 CodeTypeMember)
IsClass

取得或設定數值,表示型別是否為類別或參考型別。

IsEnum

取得或設定數值,表示型別是否為列舉型別。

IsInterface

取得或設定數值,表示型別是否為介面。

IsPartial

取得或設定值,指出型別宣告是完整的,還是部分的。

IsStruct

取得或設定值,指出型別是否為實值型別 (結構)。

LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。

(繼承來源 CodeTypeMember)
Members

取得所表示型別之類別成員的集合。

Name

取得或設定成員的名稱。

(繼承來源 CodeTypeMember)
StartDirectives

取得成員的開頭指示詞。

(繼承來源 CodeTypeMember)
TypeAttributes

取得或設定型別的屬性。

TypeParameters

取得型別宣告的型別參數。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

事件

PopulateBaseTypes

發生於第一次存取 BaseTypes 集合時。

PopulateMembers

發生於第一次存取 Members 集合時。

適用於

另請參閱