CodeTypeDeclaration Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a type declaration for a class, structure, interface, or enumeration.
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
- Inheritance
- Derived
- Attributes
Examples
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
Remarks
CodeTypeDeclaration can be used to represent code that declares a class, structure, interface, or enumeration. CodeTypeDeclaration can be used to declare a type that is nested within another type.
The BaseTypes property specifies the base type or base types of the type being declared. The Members property contains the type members, which can include methods, fields, properties, comments and other types. The TypeAttributes property indicates the TypeAttributes values for the type declaration, which indicate the type category of the type. The IsClass, IsStruct, IsEnum, and IsInterface methods indicate whether the type is a class, structure, enumeration, or interface type, respectively.
Note
Some programming languages only support the declaration of reference types, or classes. 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 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. The IsPartial property indicates whether the type declaration is complete or partial. Not all code generators support partial type declarations, so you should test for this support by calling the Supports method with the flag PartialTypes.
Constructors
CodeTypeDeclaration() |
Initializes a new instance of the CodeTypeDeclaration class. |
CodeTypeDeclaration(String) |
Initializes a new instance of the CodeTypeDeclaration class with the specified name. |
Properties
Attributes |
Gets or sets the attributes of the member. (Inherited from CodeTypeMember) |
BaseTypes |
Gets the base types of the type. |
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. |
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. (Inherited from CodeTypeMember) |
Members |
Gets the collection of class members for the represented type. |
Name |
Gets or sets the name of the member. (Inherited from CodeTypeMember) |
StartDirectives |
Gets the start directives for the member. (Inherited from 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. (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. |
PopulateMembers |
Occurs when the Members collection is accessed for the first time. |
Applies to
See also
Pripomienky
https://aka.ms/ContentUserFeedback.
Pripravujeme: V priebehu roka 2024 postupne zrušíme službu Problémy v službe GitHub ako mechanizmus pripomienok týkajúcich sa obsahu a nahradíme ju novým systémom pripomienok. Ďalšie informácie nájdete na stránke:Odoslať a zobraziť pripomienky pre