CodeAttachEventStatement 类

定义

表示向事件附加事件处理程序委托的语句。Represents a statement that attaches an event-handler delegate to an event.

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

示例

下面的示例代码演示CodeAttachEventStatement如何使用将事件处理程序附加到事件。The following example code demonstrates use of a CodeAttachEventStatement to attach an event handler with an event.

// 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可用于表示一个语句, 该语句为事件添加事件处理程序委托。CodeAttachEventStatement can be used to represent a statement that adds an event-handler delegate for an event. Event属性指示要将事件处理程序附加到的事件。The Event property indicates the event to attach the event handler to. Listener属性指示要附加的事件处理程序。The Listener property indicates the event handler to attach.

构造函数

CodeAttachEventStatement()

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

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件和委托初始化 CodeAttachEventStatement 类的新实例。Initializes a new instance of the CodeAttachEventStatement class using the specified event and delegate.

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

使用包含事件、事件名和事件处理程序委托的指定对象来初始化 CodeAttachEventStatement 类的新实例。Initializes a new instance of the CodeAttachEventStatement class using the specified object containing the event, event name, and event-handler delegate.

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives.

(继承自 CodeStatement)
Event

获取或设置要对其附加事件处理程序委托的事件。Gets or sets the event to attach an event-handler delegate to.

LinePragma

获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs.

(继承自 CodeStatement)
Listener

获取或设置要附加到事件的新事件处理程序委托。Gets or sets the new event-handler delegate to attach to the event.

StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives.

(继承自 CodeStatement)
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)

适用于