CodeDelegateCreateExpression Class
Represents an expression that creates a delegate.
System.CodeDom::CodeObject
System.CodeDom::CodeExpression
System.CodeDom::CodeDelegateCreateExpression
Assembly: System (in System.dll)
The CodeDelegateCreateExpression type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | CodeDelegateCreateExpression() | Initializes a new instance of the CodeDelegateCreateExpression class. |
![]() | CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String) | Initializes a new instance of the CodeDelegateCreateExpression class. |
| Name | Description | |
|---|---|---|
![]() | DelegateType | Gets or sets the data type of the delegate. |
![]() | MethodName | Gets or sets the name of the event handler method. |
![]() | TargetObject | Gets or sets the object that contains the event-handler method. |
![]() | UserData | Gets the user-definable data for the current object. (Inherited from CodeObject.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
CodeDelegateCreateExpression represents code that creates a delegate. CodeDelegateCreateExpression is often used with CodeAttachEventStatement or CodeRemoveEventStatement to represent an event handler to attach or remove from an event.
The DelegateType property specifies the type of delegate to create. The TargetObject property indicates the object that contains the event-handler method. The MethodName property indicates the name of the event-handler method whose method signature matches the method signature of the delegate.
In C#, a delegate creation expression is typically of the following form: new EventHandler(this.HandleEventMethod). In Visual Basic, a delegate creation expression is typically of the following form: AddressOf Me.HandleEventMethod.
The following example code uses a CodeDelegateCreateExpression to create a delegate.
// 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);
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
