CodeDelegateCreateExpression 类

定义

表示创建委托的表达式。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
继承
CodeDelegateCreateExpression
属性

示例

下面的示例代码使用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 类的新实例。Initializes a new instance of the CodeDelegateCreateExpression class.

CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

初始化 CodeDelegateCreateExpression 类的新实例。Initializes a new instance of the CodeDelegateCreateExpression class.

属性

DelegateType

获取或设置委托的数据类型。Gets or sets the data type of the delegate.

MethodName

获取或设置事件处理程序方法的名称。Gets or sets the name of the event handler method.

TargetObject

获取或设置包含事件处理程序方法的对象。Gets or sets the object that contains the event-handler method.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于