CodeTypeDelegate CodeTypeDelegate CodeTypeDelegate CodeTypeDelegate Class

Definition

Represents a delegate declaration.

public ref class CodeTypeDelegate : System::CodeDom::CodeTypeDeclaration
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeTypeDelegate : System.CodeDom.CodeTypeDeclaration
type CodeTypeDelegate = class
    inherit CodeTypeDeclaration
Public Class CodeTypeDelegate
Inherits CodeTypeDeclaration
Inheritance
Attributes

Examples

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 = gcnew CodeTypeDelegate( "TestDelegate" );
delegate1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.Object","sender" ) );
delegate1->Parameters->Add( gcnew 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);
// 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);
' 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

Remarks

CodeTypeDelegate can be used to declare a delegate type, or event handler. A delegate defines a method signature that can be used by callback 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.

Constructors

CodeTypeDelegate() CodeTypeDelegate() CodeTypeDelegate() CodeTypeDelegate()

Initializes a new instance of the CodeTypeDelegate class.

CodeTypeDelegate(String) CodeTypeDelegate(String) CodeTypeDelegate(String) CodeTypeDelegate(String)

Initializes a new instance of the CodeTypeDelegate class.

Properties

Attributes Attributes Attributes Attributes

Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
BaseTypes BaseTypes BaseTypes BaseTypes

Gets the base types of the type.

(Inherited from CodeTypeDeclaration)
Comments Comments Comments Comments

Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes CustomAttributes CustomAttributes CustomAttributes

Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives EndDirectives EndDirectives EndDirectives

Gets the end directives for the member.

(Inherited from CodeTypeMember)
IsClass IsClass IsClass IsClass

Gets or sets a value indicating whether the type is a class or reference type.

(Inherited from CodeTypeDeclaration)
IsEnum IsEnum IsEnum IsEnum

Gets or sets a value indicating whether the type is an enumeration.

(Inherited from CodeTypeDeclaration)
IsInterface IsInterface IsInterface IsInterface

Gets or sets a value indicating whether the type is an interface.

(Inherited from CodeTypeDeclaration)
IsPartial IsPartial IsPartial IsPartial

Gets or sets a value indicating whether the type declaration is complete or partial.

(Inherited from CodeTypeDeclaration)
IsStruct IsStruct IsStruct IsStruct

Gets or sets a value indicating whether the type is a value type (struct).

(Inherited from CodeTypeDeclaration)
LinePragma LinePragma LinePragma LinePragma

Gets or sets the line on which the type member statement occurs.

(Inherited from CodeTypeMember)
Members Members Members Members

Gets the collection of class members for the represented type.

(Inherited from CodeTypeDeclaration)
Name Name Name Name

Gets or sets the name of the member.

(Inherited from CodeTypeMember)
Parameters Parameters Parameters Parameters

Gets the parameters of the delegate.

ReturnType ReturnType ReturnType ReturnType

Gets or sets the return type of the delegate.

StartDirectives StartDirectives StartDirectives StartDirectives

Gets the start directives for the member.

(Inherited from CodeTypeMember)
TypeAttributes TypeAttributes TypeAttributes TypeAttributes

Gets or sets the attributes of the type.

(Inherited from CodeTypeDeclaration)
TypeParameters TypeParameters TypeParameters TypeParameters

Gets the type parameters for the type declaration.

(Inherited from CodeTypeDeclaration)
UserData UserData UserData UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Events

PopulateBaseTypes PopulateBaseTypes PopulateBaseTypes PopulateBaseTypes

Occurs when the BaseTypes collection is accessed for the first time.

(Inherited from CodeTypeDeclaration)
PopulateMembers PopulateMembers PopulateMembers PopulateMembers

Occurs when the Members collection is accessed for the first time.

(Inherited from CodeTypeDeclaration)

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to