This documentation is archived and is not being maintained.

CodeTypeDelegate Class

Represents a delegate declaration.

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

[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class CodeTypeDelegate : CodeTypeDeclaration

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.

NoteNote:

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.

The following example code demonstrates use of a CodeTypeDelegate to declare a new delegate type.

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

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: