CodeTypeDeclaration CodeTypeDeclaration CodeTypeDeclaration CodeTypeDeclaration Class

定義

表示類別、結構、介面或列舉型別的型別宣告。Represents a type declaration for a class, structure, interface, or enumeration.

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

範例

這個範例示範CodeTypeDeclaration如何使用來宣告型別。This example demonstrates using a CodeTypeDeclaration to declare a type.

// 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 can be used to represent code that declares a class, structure, interface, or enumeration. CodeTypeDeclaration可以用來宣告在另一個類型中嵌套的類型。CodeTypeDeclaration can be used to declare a type that is nested within another type.

BaseTypes屬性會指定要宣告之類型的基底類型或基底類型。The BaseTypes property specifies the base type or base types of the type being declared. Members屬性包含類型成員,其中可以包含方法、欄位、屬性、批註和其他類型。The Members property contains the type members, which can include methods, fields, properties, comments and other types. 屬性會指出類型TypeAttributes宣告的值,這表示類型的類型類別目錄。 TypeAttributesThe TypeAttributes property indicates the TypeAttributes values for the type declaration, which indicate the type category of the type. IsClassIsEnum、和方法IsInterface會分別指出類型為類別、結構、列舉或介面類別型。 IsStructThe IsClass, IsStruct, IsEnum, and IsInterface methods indicate whether the type is a class, structure, enumeration, or interface type, respectively.

注意

某些程式設計語言僅支援參考型別或類別的宣告。Some programming languages only support the declaration of reference types, or classes. 若要檢查特定語言的 CodeDOM 程式碼產生器,以支援宣告介面、列舉或實數值型別, Supports請呼叫方法來測試適當GeneratorSupport的旗標。To check a language-specific CodeDOM code generator for support for declaring interfaces, enumerations, or value types, call the Supports method to test for the appropriate GeneratorSupport flags. DeclareInterfaces指出對介面的支援DeclareEnums 、表示支援列舉,並DeclareValueTypes指出對實數值型別(例如結構)的支援。DeclareInterfaces indicates support for interfaces, DeclareEnums indicates support for enumerations, and DeclareValueTypes indicates support for value types such as structures.

您可以在一個完整的宣告中建立類別或結構實作為,或將此實作為跨多個宣告。You can build a class or a structure implementation in one complete declaration, or spread the implementation across multiple declarations. IsPartial屬性會指出型別宣告為完整或部分。The IsPartial property indicates whether the type declaration is complete or partial. 並非所有的程式碼產生器都支援部分類型宣告,因此您應該使用旗Supports PartialTypes標呼叫方法來測試這項支援。Not all code generators support partial type declarations, so you should test for this support by calling the Supports method with the flag PartialTypes.

建構函式

CodeTypeDeclaration() CodeTypeDeclaration() CodeTypeDeclaration() CodeTypeDeclaration()

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

CodeTypeDeclaration(String) CodeTypeDeclaration(String) CodeTypeDeclaration(String) CodeTypeDeclaration(String)

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

屬性

Attributes Attributes Attributes Attributes

取得或設定成員的屬性 (Attribute)。Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
BaseTypes BaseTypes BaseTypes BaseTypes

取得型別的基底型別。Gets the base types of the type.

Comments Comments Comments Comments

取得型別成員的註解集合。Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes CustomAttributes CustomAttributes CustomAttributes

取得或設定成員的自訂屬性。Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives EndDirectives EndDirectives EndDirectives

取得成員的結尾指示詞。Gets the end directives for the member.

(Inherited from CodeTypeMember)
IsClass IsClass IsClass IsClass

取得或設定數值,表示型別是否為類別或參考型別。Gets or sets a value indicating whether the type is a class or reference type.

IsEnum IsEnum IsEnum IsEnum

取得或設定數值,表示型別是否為列舉型別。Gets or sets a value indicating whether the type is an enumeration.

IsInterface IsInterface IsInterface IsInterface

取得或設定數值,表示型別是否為介面。Gets or sets a value indicating whether the type is an interface.

IsPartial IsPartial IsPartial IsPartial

取得或設定值,指出型別宣告是完整的,還是部分的。Gets or sets a value indicating whether the type declaration is complete or partial.

IsStruct IsStruct IsStruct IsStruct

取得或設定值,指出型別是否為實值型別 (結構)。Gets or sets a value indicating whether the type is a value type (struct).

LinePragma LinePragma LinePragma LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。Gets or sets the line on which the type member statement occurs.

(Inherited from CodeTypeMember)
Members Members Members Members

取得所表示型別之類別成員的集合。Gets the collection of class members for the represented type.

Name Name Name Name

取得或設定成員的名稱。Gets or sets the name of the member.

(Inherited from CodeTypeMember)
StartDirectives StartDirectives StartDirectives StartDirectives

取得成員的開頭指示詞。Gets the start directives for the member.

(Inherited from CodeTypeMember)
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

取得或設定型別的屬性。Gets or sets the attributes of the type.

TypeParameters TypeParameters TypeParameters TypeParameters

取得型別宣告的型別參數。Gets the type parameters for the type declaration.

UserData UserData UserData UserData

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

(Inherited from CodeObject)

事件

PopulateBaseTypes PopulateBaseTypes PopulateBaseTypes PopulateBaseTypes

發生於第一次存取 BaseTypes 集合時。Occurs when the BaseTypes collection is accessed for the first time.

PopulateMembers PopulateMembers PopulateMembers PopulateMembers

發生於第一次存取 Members 集合時。Occurs when the Members collection is accessed for the first time.

方法

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)

適用於

另請參閱