Freigeben über


CodeAttachEventStatement-Klasse

Stellt eine Anweisung dar, die einen Ereignishandlerdelegaten an ein Ereignis anfügt.

Namespace: System.CodeDom
Assembly: System (in system.dll)

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeAttachEventStatement
    Inherits CodeStatement
'Usage
Dim instance As CodeAttachEventStatement
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class CodeAttachEventStatement : CodeStatement
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class CodeAttachEventStatement : public CodeStatement
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class CodeAttachEventStatement extends CodeStatement
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class CodeAttachEventStatement extends CodeStatement

Hinweise

Mit CodeAttachEventStatement kann eine Anweisung dargestellt werden, die für ein Ereignis einen Ereignishandlerdelegaten hinzufügt. Die Event-Eigenschaft gibt das Ereignis an, an das der Ereignishandler angefügt werden soll. Die Listener-Eigenschaft gibt den anzufügenden Ereignishandler an.

Beispiel

Im folgenden Beispielcode wird veranschaulicht, wie mit einem CodeAttachEventStatement ein Ereignishandler an ein Ereignis angefügt wird.

' 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
// 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 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 VJ# code generator produces the following source code for the 
// preceeding example code:
// this.add_TestEvent(new System.EventHandler(this.TestMethod));

Vererbungshierarchie

System.Object
   System.CodeDom.CodeObject
     System.CodeDom.CodeStatement
      System.CodeDom.CodeAttachEventStatement

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

CodeAttachEventStatement-Member
System.CodeDom-Namespace