CodeTypeDelegate CodeTypeDelegate CodeTypeDelegate CodeTypeDelegate Class

定義

表示委派 (Delegate) 宣告。Represents a delegate declaration.

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

範例

下列範例程式碼示範CodeTypeDelegate如何使用來宣告新的委派型別。The following example code demonstrates use of a CodeTypeDelegate to declare a new delegate type.

// Declares a delegate type called TestDelegate with an EventArgs parameter.
CodeTypeDelegate^ delegate1 = gcnew CodeTypeDelegate( "TestDelegate" );
delegate1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.Object","sender" ) );
delegate1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.EventArgs","e" ) );

// A C# code generator produces the following source code for the preceeding example code:
//     public delegate void TestDelegate(object sender, System.EventArgs e);
// Declares a delegate type called TestDelegate with an EventArgs parameter.
CodeTypeDelegate delegate1 = new CodeTypeDelegate("TestDelegate");            
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.Object", "sender") );
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.EventArgs", "e") );        

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

//     public delegate void TestDelegate(object sender, System.EventArgs e);
' Declares a delegate type called TestDelegate with an EventArgs parameter.
Dim delegate1 As New CodeTypeDelegate("TestDelegate")
delegate1.Parameters.Add(New CodeParameterDeclarationExpression("System.Object", "sender"))
delegate1.Parameters.Add(New CodeParameterDeclarationExpression("System.EventArgs", "e"))

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

'	    Public Delegate Sub TestDelegate(ByVal sender As Object, ByVal e As System.EventArgs)
'		End Class

備註

CodeTypeDelegate可以用來宣告委派類型或事件處理常式。CodeTypeDelegate can be used to declare a delegate type, or event handler. 委派會定義可供回呼方法或事件處理常式使用的方法簽章。A delegate defines a method signature that can be used by callback methods or event handlers. 委派可以在命名空間層級宣告, 或在其他類型內嵌套。Delegates can be declared at the namespace level or nested inside other types. 委派無法嵌套于其他委派內。Delegates cannot be nested inside other delegates.

ReturnType屬性會指定委派所傳回之事件處理常式的資料類型。The ReturnType property specifies the data type of the event handler returned by the delegate. Parameters屬性包含委派類型的參數。The Parameters property contains the parameters for the delegate type.

CodeTypeDelegate不應該用於列舉、介面或類型宣告。CodeTypeDelegate should not be used for enumeration, interface, or type declaration. 相反地, CodeTypeDeclaration請使用做為。Instead, use CodeTypeDeclaration for those.

注意

並非所有語言都支援委派的宣告。Not all languages support the declaration of delegates. 使用旗標呼叫方法, 以判斷特定語言是否支援。 Supports DeclareDelegatesCall the Supports method with the DeclareDelegates flag to determine if it is supported in a particular language.

建構函式

CodeTypeDelegate() CodeTypeDelegate() CodeTypeDelegate() CodeTypeDelegate()

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

CodeTypeDelegate(String) CodeTypeDelegate(String) CodeTypeDelegate(String) CodeTypeDelegate(String)

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

屬性

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.

(Inherited from CodeTypeDeclaration)
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.

(Inherited from CodeTypeDeclaration)
IsEnum IsEnum IsEnum IsEnum

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

(Inherited from CodeTypeDeclaration)
IsInterface IsInterface IsInterface IsInterface

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

(Inherited from CodeTypeDeclaration)
IsPartial IsPartial IsPartial IsPartial

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

(Inherited from CodeTypeDeclaration)
IsStruct IsStruct IsStruct IsStruct

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

(Inherited from CodeTypeDeclaration)
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.

(Inherited from CodeTypeDeclaration)
Name Name Name Name

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

(Inherited from CodeTypeMember)
Parameters Parameters Parameters Parameters

取得委派的參數。Gets the parameters of the delegate.

ReturnType ReturnType ReturnType ReturnType

取得或設定委派的傳回型別 (Return Type)。Gets or sets the return type of the delegate.

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.

(Inherited from CodeTypeDeclaration)
TypeParameters TypeParameters TypeParameters TypeParameters

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

(Inherited from CodeTypeDeclaration)
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.

(Inherited from CodeTypeDeclaration)
PopulateMembers PopulateMembers PopulateMembers PopulateMembers

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

(Inherited from CodeTypeDeclaration)

方法

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)

適用於