CodeTypeDeclaration Class
Represents a type declaration for a class, structure, interface or enumeration.
For a list of all members of this type, see CodeTypeDeclaration Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeTypeMember
System.CodeDom.CodeTypeDeclaration
System.CodeDom.CodeTypeDelegate
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeTypeDeclaration Inherits CodeTypeMember [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeTypeDeclaration : CodeTypeMember [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeTypeDeclaration : public CodeTypeMember [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeTypeDeclaration extends CodeTypeMember
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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 respectively indicate whether the type is a class, structure, enumeration, or interface type.
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.
Example
[Visual Basic, C#, C++] This example demonstrates using a CodeTypeDeclaration to declare a type.
[Visual Basic] ' 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 [C#] // 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 // { // } [C++] // Creates a new type declaration. CodeTypeDeclaration* newType = new CodeTypeDeclaration( // name parameter indicates the name of the type. S"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( S"BaseType" ); // A C# code generator produces the following source code for the preceeding example code: // class TestType : BaseType // { // }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
CodeTypeDeclaration Members | System.CodeDom Namespace | CodeTypeDeclarationCollection