CodeDelegateCreateExpression 類別

定義

表示建立委派的運算式。

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

範例

下列範例程式代碼會使用 CodeDelegateCreateExpression 來建立委派。

// Defines a delegate creation expression that creates an EventHandler delegate pointing to a method named TestMethod.
CodeDelegateCreateExpression^ createDelegate1 = gcnew CodeDelegateCreateExpression( gcnew CodeTypeReference( "System.EventHandler" ),gcnew CodeThisReferenceExpression,"TestMethod" );

// Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
CodeAttachEventStatement^ attachStatement1 = gcnew CodeAttachEventStatement( gcnew CodeThisReferenceExpression,"TestEvent",createDelegate1 );

// A C# code generator produces the following source code for the preceeding example code:
//     this.TestEvent += new System.EventHandler(this.TestMethod);
// Defines a delegate creation expression that creates an EventHandler delegate pointing to a method named TestMethod.
CodeDelegateCreateExpression createDelegate1 = new CodeDelegateCreateExpression(
new CodeTypeReference( "System.EventHandler" ), new CodeThisReferenceExpression(), "TestMethod" );
// Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
CodeAttachEventStatement attachStatement1 = new CodeAttachEventStatement( new CodeThisReferenceExpression(), "TestEvent", createDelegate1 );

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

//     this.TestEvent += new System.EventHandler(this.TestMethod);
' Defines a delegate creation expression that creates an EventHandler delegate pointing to TestMethod.
Dim createDelegate1 As New CodeDelegateCreateExpression(New CodeTypeReference("System.EventHandler"), New CodeThisReferenceExpression(), "TestMethod")

' Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
Dim attachStatement1 As New CodeAttachEventStatement(New CodeThisReferenceExpression(), "TestEvent", createDelegate1)

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

'     AddHandler TestEvent, AddressOf Me.TestMethod

備註

CodeDelegateCreateExpression 表示建立委派的程序代碼。 CodeDelegateCreateExpression通常與 或 CodeRemoveEventStatement 搭配CodeAttachEventStatement使用,代表要附加或移除事件的事件處理程式。

屬性 DelegateType 會指定要建立的委派類型。 屬性 TargetObject 表示包含事件處理程式方法的物件。 屬性 MethodName 表示事件處理程式方法的名稱,其方法簽章符合委派的方法簽章。

在 C# 中,委派建立表達式通常是下列形式: new EventHandler(this.HandleEventMethod)。 在 Visual Basic 中,委派建立表達式通常是下列形式: AddressOf Me.HandleEventMethod

建構函式

CodeDelegateCreateExpression()

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

CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

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

屬性

DelegateType

取得或設定委派的資料型別。

MethodName

取得或設定事件處理常式方法的名稱。

TargetObject

取得或設定包含事件處理常式方法的物件。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於