CodeTypeDelegate 类

定义

表示委托声明。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
继承
属性

示例

下面的示例代码演示CodeTypeDelegate如何使用声明新的委托类型。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

注解

CodeTypeDelegate可用于声明委托类型或事件处理程序。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.

ReturnType属性指定委托返回的事件处理程序的数据类型。The ReturnType property specifies the data type of the event handler returned by the delegate. Parameters属性包含委托类型的参数。The Parameters property contains the parameters for the delegate type.

CodeTypeDelegate不应用于枚举、接口或类型声明。CodeTypeDelegate should not be used for enumeration, interface, or type declaration. 而是将CodeTypeDeclaration用于这些。Instead, use CodeTypeDeclaration for those.

备注

并非所有语言都支持委托声明。Not all languages support the declaration of delegates. 使用标志调用Supports方法, 以确定特定语言是否支持此方法。 DeclareDelegatesCall the Supports method with the DeclareDelegates flag to determine if it is supported in a particular language.

构造函数

CodeTypeDelegate()

初始化 CodeTypeDelegate 类的新实例。Initializes a new instance of the CodeTypeDelegate class.

CodeTypeDelegate(String)

初始化 CodeTypeDelegate 类的新实例。Initializes a new instance of the CodeTypeDelegate class.

属性

Attributes

获取或设置成员的特性。Gets or sets the attributes of the member.

(继承自 CodeTypeMember)
BaseTypes

获取类型的基类型。Gets the base types of the type.

(继承自 CodeTypeDeclaration)
Comments

获取类型成员的注释集合。Gets the collection of comments for the type member.

(继承自 CodeTypeMember)
CustomAttributes

获取或设置成员的自定义特性。Gets or sets the custom attributes of the member.

(继承自 CodeTypeMember)
EndDirectives

获取成员的结束指令。Gets the end directives for the member.

(继承自 CodeTypeMember)
IsClass

获取或设置一个值,该值指示该类型是否是类或引用类型。Gets or sets a value indicating whether the type is a class or reference type.

(继承自 CodeTypeDeclaration)
IsEnum

获取或设置一个值,该值指示该类型是否是枚举。Gets or sets a value indicating whether the type is an enumeration.

(继承自 CodeTypeDeclaration)
IsInterface

获取或设置一个值,该值指示该类型是否是接口。Gets or sets a value indicating whether the type is an interface.

(继承自 CodeTypeDeclaration)
IsPartial

获取或设置一个值,该值指示该类型声明是完整的类型声明还是分部类型声明。Gets or sets a value indicating whether the type declaration is complete or partial.

(继承自 CodeTypeDeclaration)
IsStruct

获取或设置一个值,该值指示该类型是不是值类型(结构)。Gets or sets a value indicating whether the type is a value type (struct).

(继承自 CodeTypeDeclaration)
LinePragma

获取或设置类型成员语句所在的行。Gets or sets the line on which the type member statement occurs.

(继承自 CodeTypeMember)
Members

获取所表示的类型的类成员的集合。Gets the collection of class members for the represented type.

(继承自 CodeTypeDeclaration)
Name

获取或设置成员名。Gets or sets the name of the member.

(继承自 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.

(继承自 CodeTypeMember)
TypeAttributes

获取或设置类型的特性。Gets or sets the attributes of the type.

(继承自 CodeTypeDeclaration)
TypeParameters

获取类型声明的类型参数。Gets the type parameters for the type declaration.

(继承自 CodeTypeDeclaration)
UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

事件

PopulateBaseTypes

当首次访问 BaseTypes 集合时发生。Occurs when the BaseTypes collection is accessed for the first time.

(继承自 CodeTypeDeclaration)
PopulateMembers

当首次访问 Members 集合时发生。Occurs when the Members collection is accessed for the first time.

(继承自 CodeTypeDeclaration)

适用于