CodeDelegateCreateExpression Klasa

Definicja

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
CodeDelegateCreateExpression
Atrybuty

Przykłady

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

Uwagi

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.

Konstruktory

CodeDelegateCreateExpression()

Inicjuje nowe wystąpienie klasy CodeDelegateCreateExpression.

CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

Inicjuje nowe wystąpienie klasy CodeDelegateCreateExpression.

Właściwości

DelegateType

Pobiera lub ustawia typ danych delegata.

MethodName

Pobiera lub ustawia nazwę metody obsługi zdarzeń.

TargetObject

Pobiera lub ustawia obiekt, który zawiera metodę obsługi zdarzeń.

UserData

Pobiera dane zdefiniowane przez użytkownika dla bieżącego obiektu.

(Odziedziczone po CodeObject)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy