CodeTypeDeclaration 类

定义

表示类、结构、接口或枚举的类型声明。Represents a type declaration for a class, structure, interface, or enumeration.

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

示例

此示例演示CodeTypeDeclaration如何使用声明类型。This example demonstrates using a CodeTypeDeclaration to declare a type.

// 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 can be used to represent code that declares a class, structure, interface, or enumeration. CodeTypeDeclaration可用于声明嵌套在另一类型中的类型。CodeTypeDeclaration can be used to declare a type that is nested within another type.

BaseTypes属性指定正在声明的类型的基类型或基类型。The BaseTypes property specifies the base type or base types of the type being declared. Members属性包含类型成员,这些成员可以包含方法、字段、属性、注释和其他类型。The Members property contains the type members, which can include methods, fields, properties, comments and other types. 属性指示类型声明的值,它指示类型的类型类别。TypeAttributes TypeAttributesThe TypeAttributes property indicates the TypeAttributes values for the type declaration, which indicate the type category of the type. IsClassIsEnum、和方法IsInterface分别指示该类型是类、结构、枚举还是接口类型。 IsStructThe IsClass, IsStruct, IsEnum, and IsInterface methods indicate whether the type is a class, structure, enumeration, or interface type, respectively.

备注

某些编程语言仅支持引用类型或类的声明。Some programming languages only support the declaration of reference types, or classes. 若要检查特定于语言的 CodeDOM 代码生成器是否支持声明接口、枚举或值类型,请调用Supports方法来测试适当GeneratorSupport的标志。To check a language-specific CodeDOM code generator for support for declaring interfaces, enumerations, or value types, call the Supports method to test for the appropriate GeneratorSupport flags. DeclareInterfaces指示支持接口, DeclareEnums表示支持枚举,并DeclareValueTypes指示对值类型(如结构)的支持。DeclareInterfaces indicates support for interfaces, DeclareEnums indicates support for enumerations, and DeclareValueTypes indicates support for value types such as structures.

您可以在一个完整的声明中生成一个类或结构实现,也可以跨多个声明来实现该实现。You can build a class or a structure implementation in one complete declaration, or spread the implementation across multiple declarations. IsPartial属性指示类型声明是完整的还是部分的。The IsPartial property indicates whether the type declaration is complete or partial. 并非所有代码生成器都支持分部类型声明,因此,您应通过使用标志Supports PartialTypes调用方法来测试此支持。Not all code generators support partial type declarations, so you should test for this support by calling the Supports method with the flag PartialTypes.

构造函数

CodeTypeDeclaration()

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

CodeTypeDeclaration(String)

用指定的名称初始化 CodeTypeDeclaration 类的新实例。Initializes a new instance of the CodeTypeDeclaration class with the specified name.

属性

Attributes

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

(继承自 CodeTypeMember)
BaseTypes

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

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.

IsEnum

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

IsInterface

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

IsPartial

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

IsStruct

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

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.

Name

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

(继承自 CodeTypeMember)
StartDirectives

获取成员的开始指令。Gets the start directives for the member.

(继承自 CodeTypeMember)
TypeAttributes

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

TypeParameters

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

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.

PopulateMembers

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

适用于

另请参阅