CodeDelegateCreateExpression Clase

Definición

Representa una expresión que crea un delegado.

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
Herencia
CodeDelegateCreateExpression
Atributos

Ejemplos

En el código de ejemplo siguiente se usa un CodeDelegateCreateExpression para crear un delegado.

// 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

Comentarios

CodeDelegateCreateExpression representa el código que crea un delegado. CodeDelegateCreateExpression a menudo se usa con CodeAttachEventStatement o CodeRemoveEventStatement para representar un controlador de eventos para adjuntar o quitar de un evento.

La DelegateType propiedad especifica el tipo de delegado que se va a crear. La TargetObject propiedad indica el objeto que contiene el método event-handler. La MethodName propiedad indica el nombre del método del controlador de eventos cuya firma de método coincide con la firma del método del delegado.

En C#, una expresión de creación de delegados suele tener la siguiente forma: new EventHandler(this.HandleEventMethod). En Visual Basic, una expresión de creación de delegados suele tener el siguiente formato: AddressOf Me.HandleEventMethod.

Constructores

CodeDelegateCreateExpression()

Inicializa una nueva instancia de la clase CodeDelegateCreateExpression.

CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

Inicializa una nueva instancia de la clase CodeDelegateCreateExpression.

Propiedades

DelegateType

Obtiene o establece el tipo de datos del delegado.

MethodName

Obtiene o establece el nombre del método de control de eventos.

TargetObject

Obtiene o establece el objeto que contiene el método de control de eventos.

UserData

Obtiene los datos definibles por el usuario para el objeto actual.

(Heredado de CodeObject)

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a