Represents an expression that creates a delegate.
Assembly: System (in System.dll)
Thetype exposes the following members.
|CodeDelegateCreateExpression()||Initializes a new instance of the class.|
|CodeDelegateCreateExpression(CodeTypeReference, CodeExpression, String)||Initializes a new instance of the class.|
|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.)|
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 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);
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