CodeAttachEventStatement 类

定义

表示向事件附加事件处理程序委托的语句。

public ref class CodeAttachEventStatement : System::CodeDom::CodeStatement
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
type CodeAttachEventStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttachEventStatement = class
    inherit CodeStatement
Public Class CodeAttachEventStatement
Inherits CodeStatement
继承
CodeAttachEventStatement
属性

示例

以下示例代码演示如何使用 将 CodeAttachEventStatement 事件处理程序与 事件一起附加。

// 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

注解

CodeAttachEventStatement 可用于表示为事件添加事件处理程序委托的语句。 属性 Event 指示要向其附加事件处理程序的事件。 属性 Listener 指示要附加的事件处理程序。

构造函数

CodeAttachEventStatement()

初始化 CodeAttachEventStatement 类的新实例。

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件和委托初始化 CodeAttachEventStatement 类的新实例。

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

使用包含事件、事件名和事件处理程序委托的指定对象来初始化 CodeAttachEventStatement 类的新实例。

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。

(继承自 CodeStatement)
Event

获取或设置要对其附加事件处理程序委托的事件。

LinePragma

获取或设置代码语句所在的行。

(继承自 CodeStatement)
Listener

获取或设置要附加到事件的新事件处理程序委托。

StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。

(继承自 CodeStatement)
UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于