Επεξεργασία

Κοινή χρήση μέσω


CodeTypeDelegate Class

Definition

Represents a delegate declaration.

public ref class CodeTypeDelegate : System::CodeDom::CodeTypeDeclaration
public class CodeTypeDelegate : System.CodeDom.CodeTypeDeclaration
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeTypeDelegate : System.CodeDom.CodeTypeDeclaration
type CodeTypeDelegate = class
    inherit CodeTypeDeclaration
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
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()

Initializes a new instance of the CodeTypeDelegate class.

CodeTypeDelegate(String)

Initializes a new instance of the CodeTypeDelegate class.

Properties

Attributes

Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
BaseTypes

Gets the base types of the type.

(Inherited from CodeTypeDeclaration)
Comments

Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes

Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives

Gets the end directives for the member.

(Inherited from CodeTypeMember)
IsClass

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

(Inherited from CodeTypeDeclaration)
IsEnum

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

(Inherited from CodeTypeDeclaration)
IsInterface

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

(Inherited from CodeTypeDeclaration)
IsPartial

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

(Inherited from CodeTypeDeclaration)
IsStruct

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

(Inherited from CodeTypeDeclaration)
LinePragma

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

(Inherited from CodeTypeMember)
Members

Gets the collection of class members for the represented type.

(Inherited from CodeTypeDeclaration)
Name

Gets or sets the name of the member.

(Inherited from CodeTypeMember)
Parameters

Gets the parameters of the delegate.

ReturnType

Gets or sets the return type of the delegate.

StartDirectives

Gets the start directives for the member.

(Inherited from CodeTypeMember)
TypeAttributes

Gets or sets the attributes of the type.

(Inherited from CodeTypeDeclaration)
TypeParameters

Gets the type parameters for the type declaration.

(Inherited from CodeTypeDeclaration)
UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

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

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(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)

Events

PopulateBaseTypes

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

(Inherited from CodeTypeDeclaration)
PopulateMembers

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

(Inherited from CodeTypeDeclaration)

Applies to