CodeDelegateCreateExpression Klasa
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Reprezentuje wyrażenie, które tworzy delegata.
public ref class CodeDelegateCreateExpression : System::CodeDom::CodeExpression
public class CodeDelegateCreateExpression : System.CodeDom.CodeExpression
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeDelegateCreateExpression : System.CodeDom.CodeExpression
type CodeDelegateCreateExpression = class
inherit CodeExpression
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeDelegateCreateExpression = class
inherit CodeExpression
Public Class CodeDelegateCreateExpression
Inherits CodeExpression
- Dziedziczenie
- Atrybuty
Poniższy przykładowy kod używa elementu do CodeDelegateCreateExpression utworzenia delegata.
// 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 reprezentuje kod, który tworzy delegata. CodeDelegateCreateExpression jest często używany z programem obsługi zdarzeń CodeAttachEventStatement lub CodeRemoveEventStatement do reprezentowania programu obsługi zdarzeń w celu dołączenia lub usunięcia z zdarzenia.
Właściwość DelegateType określa typ delegata do utworzenia. Właściwość TargetObject wskazuje obiekt, który zawiera metodę obsługi zdarzeń. Właściwość MethodName wskazuje nazwę metody obsługi zdarzeń, której sygnatura metody jest zgodna z podpisem metody delegata.
W języku C# wyrażenie tworzenia delegata ma zwykle następującą postać: new EventHandler(this.HandleEventMethod)
. W języku Visual Basic wyrażenie tworzenia delegata ma zwykle następującą postać: AddressOf Me.HandleEventMethod
.
Code |
Inicjuje nowe wystąpienie klasy CodeDelegateCreateExpression. |
Code |
Inicjuje nowe wystąpienie klasy CodeDelegateCreateExpression. |
Delegate |
Pobiera lub ustawia typ danych delegata. |
Method |
Pobiera lub ustawia nazwę metody obsługi zdarzeń. |
Target |
Pobiera lub ustawia obiekt, który zawiera metodę obsługi zdarzeń. |
User |
Pobiera dane zdefiniowane przez użytkownika dla bieżącego obiektu. (Odziedziczone po CodeObject) |
Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
Get |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
Get |
Type Pobiera wartość bieżącego wystąpienia. (Odziedziczone po Object) |
Memberwise |
Tworzy płytkią kopię bieżącego Objectelementu . (Odziedziczone po Object) |
To |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |
Produkt | Wersje |
---|---|
.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 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: