Čítať v angličtine Upraviť

Zdieľať cez


CodeAttachEventStatement Class

Definition

Represents a statement that attaches an event-handler delegate to an event.

C#
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
Inheritance
CodeAttachEventStatement
Attributes

Examples

The following example code demonstrates use of a CodeAttachEventStatement to attach an event handler with an event.

C#
// 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);

Remarks

CodeAttachEventStatement can be used to represent a statement that adds an event-handler delegate for an event. The Event property indicates the event to attach the event handler to. The Listener property indicates the event handler to attach.

Constructors

CodeAttachEventStatement()

Initializes a new instance of the CodeAttachEventStatement class.

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

Initializes a new instance of the CodeAttachEventStatement class using the specified event and delegate.

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

Initializes a new instance of the CodeAttachEventStatement class using the specified object containing the event, event name, and event-handler delegate.

Properties

EndDirectives

Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from 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.

(Inherited from CodeStatement)
Listener

Gets or sets the new event-handler delegate to attach to the event.

StartDirectives

Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Produkt Verzie
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10