CodeTypeDeclaration 类

定义

表示类、结构、接口或枚举的类型声明。

public ref class CodeTypeDeclaration : System::CodeDom::CodeTypeMember
public class CodeTypeDeclaration : System.CodeDom.CodeTypeMember
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeTypeDeclaration : System.CodeDom.CodeTypeMember
type CodeTypeDeclaration = class
    inherit CodeTypeMember
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeTypeDeclaration = class
    inherit CodeTypeMember
Public Class CodeTypeDeclaration
Inherits CodeTypeMember
继承
CodeTypeDeclaration
派生
属性

示例

此示例演示如何使用 CodeTypeDeclaration 声明类型。

// Creates a new type declaration.

// name parameter indicates the name of the type.
CodeTypeDeclaration^ newType = gcnew CodeTypeDeclaration( "TestType" );

// Sets the member attributes for the type to private.
newType->Attributes = MemberAttributes::Private;

// Sets a base class which the type inherits from.
newType->BaseTypes->Add( "BaseType" );

// A C# code generator produces the following source code for the preceeding example code:
// class TestType : BaseType
// {
// }
// Creates a new type declaration.
CodeTypeDeclaration newType = new CodeTypeDeclaration(
    // name parameter indicates the name of the type.
    "TestType");
// Sets the member attributes for the type to private.
newType.Attributes = MemberAttributes.Private;
// Sets a base class which the type inherits from.
newType.BaseTypes.Add( "BaseType" );

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

// class TestType : BaseType
// {
// }
' Creates a new type declaration.
Dim newType As New CodeTypeDeclaration("TestType")
   ' name parameter indicates the name of the type.
   ' Sets the member attributes for the type to private.
   newType.Attributes = MemberAttributes.Private
   ' Sets a base class which the type inherits from.
   newType.BaseTypes.Add("BaseType")

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

' Class TestType
'    Inherits BaseType
' End Class

注解

CodeTypeDeclaration 可用于表示声明类、结构、接口或枚举的代码。 CodeTypeDeclaration 可用于声明嵌套在另一类型中的类型。

属性 BaseTypes 指定要声明的类型的基类型或基类型。 属性 Members 包含类型成员,可以包括方法、字段、属性、注释和其他类型。 属性 TypeAttributes 指示 TypeAttributes 类型声明的值,这些值指示类型的类型类别。 IsClassIsStructIsEnumIsInterface 方法分别指示类型是类、结构、枚举还是接口类型。

注意

某些编程语言仅支持引用类型或类的声明。 若要检查语言特定的 CodeDOM 代码生成器以支持声明接口、枚举或值类型,请调用 Supports 方法来测试相应的GeneratorSupport标志。 DeclareInterfaces 指示对接口的支持, DeclareEnums 指示对枚举的支持,并 DeclareValueTypes 指示对值类型(如结构)的支持。

可以在一个完整声明中生成类或结构实现,也可以跨多个声明分散实现。 属性 IsPartial 指示类型声明是完整声明还是部分声明。 并非所有代码生成器都支持分部类型声明,因此应通过使用 标志 PartialTypes调用 Supports 方法来测试此支持。

构造函数

CodeTypeDeclaration()

初始化 CodeTypeDeclaration 类的新实例。

CodeTypeDeclaration(String)

用指定的名称初始化 CodeTypeDeclaration 类的新实例。

属性

Attributes

获取或设置成员的特性。

(继承自 CodeTypeMember)
BaseTypes

获取类型的基类型。

Comments

获取类型成员的注释集合。

(继承自 CodeTypeMember)
CustomAttributes

获取或设置成员的自定义特性。

(继承自 CodeTypeMember)
EndDirectives

获取成员的结束指令。

(继承自 CodeTypeMember)
IsClass

获取或设置一个值,该值指示该类型是否是类或引用类型。

IsEnum

获取或设置一个值,该值指示该类型是否是枚举。

IsInterface

获取或设置一个值,该值指示该类型是否是接口。

IsPartial

获取或设置一个值,该值指示该类型声明是完整的类型声明还是分部类型声明。

IsStruct

获取或设置一个值,该值指示该类型是不是值类型(结构)。

LinePragma

获取或设置类型成员语句所在的行。

(继承自 CodeTypeMember)
Members

获取所表示的类型的类成员的集合。

Name

获取或设置成员名。

(继承自 CodeTypeMember)
StartDirectives

获取成员的开始指令。

(继承自 CodeTypeMember)
TypeAttributes

获取或设置类型的特性。

TypeParameters

获取类型声明的类型参数。

UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

事件

PopulateBaseTypes

当首次访问 BaseTypes 集合时发生。

PopulateMembers

当首次访问 Members 集合时发生。

适用于

另请参阅