CodeTypeDeclaration Class
TOC
Collapse the table of content
Expand the table of content

CodeTypeDeclaration Class

 

Represents a type declaration for a class, structure, interface, or enumeration.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeTypeMember
      System.CodeDom.CodeTypeDeclaration
        System.CodeDom.CodeTypeDelegate

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeTypeDeclaration : CodeTypeMember

NameDescription
System_CAPS_pubmethodCodeTypeDeclaration()

Initializes a new instance of the CodeTypeDeclaration class.

System_CAPS_pubmethodCodeTypeDeclaration(String)

Initializes a new instance of the CodeTypeDeclaration class with the specified name.

NameDescription
System_CAPS_pubpropertyAttributes

Gets or sets the attributes of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyBaseTypes

Gets the base types of the type.

System_CAPS_pubpropertyComments

Gets the collection of comments for the type member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyCustomAttributes

Gets or sets the custom attributes of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyEndDirectives

Gets the end directives for the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyIsClass

Gets or sets a value indicating whether the type is a class or reference type.

System_CAPS_pubpropertyIsEnum

Gets or sets a value indicating whether the type is an enumeration.

System_CAPS_pubpropertyIsInterface

Gets or sets a value indicating whether the type is an interface.

System_CAPS_pubpropertyIsPartial

Gets or sets a value indicating whether the type declaration is complete or partial.

System_CAPS_pubpropertyIsStruct

Gets or sets a value indicating whether the type is a value type (struct).

System_CAPS_pubpropertyLinePragma

Gets or sets the line on which the type member statement occurs.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyMembers

Gets the collection of class members for the represented type.

System_CAPS_pubpropertyName

Gets or sets the name of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyStartDirectives

Gets the start directives for the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyTypeAttributes

Gets or sets the attributes of the type.

System_CAPS_pubpropertyTypeParameters

Gets the type parameters for the type declaration.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventPopulateBaseTypes

Occurs when the BaseTypes collection is accessed for the first time.

System_CAPS_pubeventPopulateMembers

Occurs when the Members collection is accessed for the first time.

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.

System_CAPS_noteNote

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.

This example demonstrates using a CodeTypeDeclaration to declare a type.

// 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
// {
// }

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft