CodeDelegateCreateExpression Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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
- Atributos
Ejemplos
En el código de ejemplo siguiente se usa para CodeDelegateCreateExpression crear un delegado.
// 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 event-handler 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 el formato siguiente: new EventHandler(this.HandleEventMethod). En Visual Basic, una expresión de creación de delegados suele tener la siguiente forma: AddressOf Me.HandleEventMethod.
Constructores
| Nombre | Description |
|---|---|
| CodeDelegateCreateExpression() |
Inicializa una nueva instancia de la clase CodeDelegateCreateExpression. |
| CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String) |
Inicializa una nueva instancia de la clase CodeDelegateCreateExpression. |
Propiedades
| Nombre | Description |
|---|---|
| DelegateType |
Obtiene o establece el tipo de datos del delegado. |
| MethodName |
Obtiene o establece el nombre del método de controlador de eventos. |
| TargetObject |
Obtiene o establece el objeto que contiene el método event-handler. |
| UserData |
Obtiene los datos definibles por el usuario para el objeto actual. (Heredado de CodeObject) |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetHashCode() |
Actúa como función hash predeterminada. (Heredado de Object) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |