CodeDelegateCreateExpression CodeDelegateCreateExpression CodeDelegateCreateExpression CodeDelegateCreateExpression Class

定義

表示建立委派的運算式。Represents an expression that creates a delegate.

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

範例

下列範例程式碼會使用CodeDelegateCreateExpression來建立委派。The following example code uses a CodeDelegateCreateExpression to create a delegate.

// 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 represents code that creates a delegate. CodeDelegateCreateExpression通常與CodeAttachEventStatementCodeRemoveEventStatement搭配使用, 代表要從事件中附加或移除的事件處理常式。CodeDelegateCreateExpression is often used with CodeAttachEventStatement or CodeRemoveEventStatement to represent an event handler to attach or remove from an event.

DelegateType屬性會指定要建立的委派類型。The DelegateType property specifies the type of delegate to create. TargetObject屬性會指出包含事件處理常式方法的物件。The TargetObject property indicates the object that contains the event-handler method. MethodName屬性會指出其方法簽章符合委派之方法簽章的事件處理常式方法的名稱。The MethodName property indicates the name of the event-handler method whose method signature matches the method signature of the delegate.

在C#中, 委派建立運算式的格式通常如下: new EventHandler(this.HandleEventMethod)In C#, a delegate creation expression is typically of the following form: new EventHandler(this.HandleEventMethod). 在 Visual Basic 中, 委派建立運算式的格式通常如下: AddressOf Me.HandleEventMethodIn Visual Basic, a delegate creation expression is typically of the following form: AddressOf Me.HandleEventMethod.

建構函式

CodeDelegateCreateExpression() CodeDelegateCreateExpression() CodeDelegateCreateExpression() CodeDelegateCreateExpression()

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

CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String) CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String) CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String) CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

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

屬性

DelegateType DelegateType DelegateType DelegateType

取得或設定委派的資料型別。Gets or sets the data type of the delegate.

MethodName MethodName MethodName MethodName

取得或設定事件處理常式方法的名稱。Gets or sets the name of the event handler method.

TargetObject TargetObject TargetObject TargetObject

取得或設定包含事件處理常式方法的物件。Gets or sets the object that contains the event-handler method.

UserData UserData UserData UserData

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

(Inherited from CodeObject)

方法

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)

適用於