CodeDelegateCreateExpression Class
Represents an expression that creates a delegate.
Assembly: System (in System.dll)
System.CodeDom::CodeObject
System.CodeDom::CodeExpression
System.CodeDom::CodeDelegateCreateExpression
| 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 the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | 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);
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


