CodeTypeReference CodeTypeReference CodeTypeReference CodeTypeReference Class

Definition

Represents a reference to a type.

public ref class CodeTypeReference : System::CodeDom::CodeObject
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeTypeReference : System.CodeDom.CodeObject
type CodeTypeReference = class
    inherit CodeObject
Public Class CodeTypeReference
Inherits CodeObject
Inheritance
CodeTypeReferenceCodeTypeReferenceCodeTypeReferenceCodeTypeReference
Attributes

Examples

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)
// Creates a reference to the System.DateTime type.
CodeTypeReference typeRef1 = new CodeTypeReference("System.DateTime");

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression typeof1 = new 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, new CodeGeneratorOptions());
// The code generator produces the following source code for the preceeding example code:
//    typeof(System.DateTime)
' Creates a reference to the System.DateTime type.
Dim typeRef1 As New CodeTypeReference("System.DateTime")

' Creates a typeof expression for the specified type reference.
Dim typeof1 As New CodeTypeOfExpression(typeRef1)

' Create a Visual Basic code provider
Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")

' Generate code and send the output to the console
provider.GenerateCodeFromExpression(typeof1, Console.Out, new CodeGeneratorOptions())
' The code generator produces the following source code for the preceeding example code:
'    GetType(Date)

Remarks

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.

Constructors

CodeTypeReference() CodeTypeReference() CodeTypeReference() CodeTypeReference()

Initializes a new instance of the CodeTypeReference class.

CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter)

Initializes a new instance of the CodeTypeReference class using the specified code type parameter.

CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32)

Initializes a new instance of the CodeTypeReference class using the specified array type and rank.

CodeTypeReference(String) CodeTypeReference(String) CodeTypeReference(String) CodeTypeReference(String)

Initializes a new instance of the CodeTypeReference class using the specified type name.

CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions)

Initializes a new instance of the CodeTypeReference class using the specified type name and code type reference option.

CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[])

Initializes a new instance of the CodeTypeReference class using the specified type name and type arguments.

CodeTypeReference(String, Int32) CodeTypeReference(String, Int32) CodeTypeReference(String, Int32) CodeTypeReference(String, Int32)

Initializes a new instance of the CodeTypeReference class using the specified array type name and rank.

CodeTypeReference(Type) CodeTypeReference(Type) CodeTypeReference(Type) CodeTypeReference(Type)

Initializes a new instance of the CodeTypeReference class using the specified type.

CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions)

Initializes a new instance of the CodeTypeReference class using the specified type and code type reference.

Properties

ArrayElementType ArrayElementType ArrayElementType ArrayElementType

Gets or sets the type of the elements in the array.

ArrayRank ArrayRank ArrayRank ArrayRank

Gets or sets the array rank of the array.

BaseType BaseType BaseType BaseType

Gets or sets the name of the type being referenced.

Options Options Options Options

Gets or sets the code type reference option.

TypeArguments TypeArguments TypeArguments TypeArguments

Gets the type arguments for the current generic type reference.

UserData UserData UserData UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to