CodeDelegateCreateExpression Class

 

Represents an expression that creates a delegate.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeExpression
      System.CodeDom.CodeDelegateCreateExpression

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeDelegateCreateExpression : CodeExpression

NameDescription
System_CAPS_pubmethodCodeDelegateCreateExpression()

Initializes a new instance of the CodeDelegateCreateExpression class.

System_CAPS_pubmethodCodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)

Initializes a new instance of the CodeDelegateCreateExpression class.

NameDescription
System_CAPS_pubpropertyDelegateType

Gets or sets the data type of the delegate.

System_CAPS_pubpropertyMethodName

Gets or sets the name of the event handler method.

System_CAPS_pubpropertyTargetObject

Gets or sets the object that contains the event-handler method.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

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 = 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);

.NET Framework
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.

Return to top
Show: