This documentation is archived and is not being maintained.

CodeTypeDelegate Class

Represents a delegate declaration.

For a list of all members of this type, see CodeTypeDelegate Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeTypeMember
         System.CodeDom.CodeTypeDeclaration
            System.CodeDom.CodeTypeDelegate

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeTypeDelegate
   Inherits CodeTypeDeclaration
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeTypeDelegate : CodeTypeDeclaration
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeTypeDelegate : public CodeTypeDeclaration
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeTypeDelegate extends CodeTypeDeclaration

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

CodeTypeDelegate can be used to declare a delegate type, or event handler. A delegate defines a method signature that can be used by calback methods or event handlers. Delegates can be declared at the namespace level or nested inside other types. Delegates cannot be nested inside other delegates.

The ReturnType property specifies the data type of the event handler returned by the delegate. The Parameters property contains the parameters for the delegate type.

CodeTypeDelegate should not be used for enumeration, interface, or type declaration. Instead, use CodeTypeDeclaration for those.

Note   Not all languages support the declaration of delegates. Call the Supports method with the DeclareDelegates flag to determine if it is supported in a particular language.

Example

[Visual Basic, C#, C++] The following example code demonstrates use of a CodeTypeDelegate to declare a new delegate type.

[Visual Basic] 
' Declares a delegate type called TestDelegate with an EventArgs parameter.
Dim delegate1 As New CodeTypeDelegate("TestDelegate")
delegate1.Parameters.Add(New CodeParameterDeclarationExpression("System.Object", "sender"))
delegate1.Parameters.Add(New CodeParameterDeclarationExpression("System.EventArgs", "e"))

' A Visual Basic code generator produces the following source code for the preceeding example code:

'        Public Delegate Sub TestDelegate(ByVal sender As Object, ByVal e As System.EventArgs)
'        End Class

[C#] 
// Declares a delegate type called TestDelegate with an EventArgs parameter.
CodeTypeDelegate delegate1 = new CodeTypeDelegate("TestDelegate");            
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.Object", "sender") );
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.EventArgs", "e") );        

// A C# code generator produces the following source code for the preceeding example code:

//     public delegate void TestDelegate(object sender, System.EventArgs e);

[C++] 
// Declares a delegate type called TestDelegate with an EventArgs parameter.
CodeTypeDelegate* delegate1 = new CodeTypeDelegate(S"TestDelegate");            
delegate1->Parameters->Add( new CodeParameterDeclarationExpression(S"System.Object", S"sender") );
delegate1->Parameters->Add( new CodeParameterDeclarationExpression(S"System.EventArgs", S"e") );        

// A C# code generator produces the following source code for the preceeding example code:

//     public delegate void TestDelegate(object sender, System.EventArgs e);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeTypeDelegate Members | System.CodeDom Namespace

Show: