CodeTypeReference Class
Represents a reference to a type.
Assembly: System (in System.dll)
The CodeTypeReference type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | CodeTypeReference() | Initializes a new instance of the CodeTypeReference class. |
![]() | CodeTypeReference(CodeTypeParameter) | Initializes a new instance of the CodeTypeReference class using the specified code type parameter. |
![]() | CodeTypeReference(String) | Initializes a new instance of the CodeTypeReference class using the specified type name. |
![]() | CodeTypeReference(Type) | Initializes a new instance of the CodeTypeReference class using the specified type. |
![]() | CodeTypeReference(CodeTypeReference, Int32) | Initializes a new instance of the CodeTypeReference class using the specified array type and rank. |
![]() | CodeTypeReference(String, array<CodeTypeReference>) | Initializes a new instance of the CodeTypeReference class using the specified type name and type arguments. |
![]() | CodeTypeReference(String, CodeTypeReferenceOptions) | Initializes a new instance of the CodeTypeReference class using the specified type name and code type reference option. |
![]() | CodeTypeReference(String, Int32) | Initializes a new instance of the CodeTypeReference class using the specified array type name and rank. |
![]() | CodeTypeReference(Type, CodeTypeReferenceOptions) | Initializes a new instance of the CodeTypeReference class using the specified type and code type reference. |
| Name | Description | |
|---|---|---|
![]() | ArrayElementType | Gets or sets the type of the elements in the array. |
![]() | ArrayRank | Gets or sets the array rank of the array. |
![]() | BaseType | Gets or sets the name of the type being referenced. |
![]() | Options | Gets or sets the code type reference option. |
![]() | TypeArguments | Gets the type arguments for the current generic type reference. |
![]() | UserData | Gets the user-definable data for the current object. (Inherited from CodeObject.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (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.) |
A CodeTypeReference object is used to represent a type for CodeDOM objects. When CodeDOM types have a Type property, it is of type CodeTypeReference. For example, the CodeMemberField::Type property is a CodeTypeReference that represents a field's data type.
A CodeTypeReference can be initialized with a Type object or a string. It is generally recommended to use a Type to do this, although it may not always be possible. If initializing an instance of this class with a string, it is strongly recommended to always use fully qualified types, such as "System.Console" instead of just "Console", because not all languages support importing namespaces. Array types can be specified by either passing in a type object for an array or using one of the constructors that accept rank as a parameter.
The BaseType property specifies the name of the type to reference. For references to array types, the ArrayElementType property indicates the type of the elements of the array, and the ArrayRank property indicates the number of dimensions in the array.
The following example demonstrates use of a CodeTypeReference to represent a reference to a type.
// Creates a reference to the System.DateTime type. CodeTypeReference^ typeRef1 = gcnew CodeTypeReference("System.DateTime"); // Creates a typeof expression for the specified type reference. CodeTypeOfExpression^ typeof1 = gcnew CodeTypeOfExpression(typeRef1); // Create a C# code provider CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp"); // Generate code and send the output to the console provider->GenerateCodeFromExpression(typeof1, Console::Out, gcnew CodeGeneratorOptions()); // The code generator produces the following source code for the preceeding example code: // typeof(System.DateTime)
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
