Export (0) Print
Expand All

CodeTypeReference Class

Represents a reference to a type.

For a list of all members of this type, see CodeTypeReference Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeTypeReference

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeTypeReference
   Inherits CodeObject
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeTypeReference : CodeObject
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeTypeReference : public CodeObject
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeTypeReference extends CodeObject

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

CodeTypeReference can be used to represent a type to many kinds of CodeDOM objects. Some objects and properties in the System.CodeDom namespace use this type of object to store references to data types.

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 an array of Type objects 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.

Example

[Visual Basic, C#, C++] The following example demonstrates use of a CodeTypeReference to represent a reference to a type.

[Visual Basic] 
' 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)

' A Visual Basic code generator produces the following source code for the preceeding example code:    

'       GetType(System.DateTime)            

[C#] 
// 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);

// A C# code generator produces the following source code for the preceeding example code:    

//    typeof(System.DateTime);            

[C++] 
// Creates a reference to the System.DateTime type.
CodeTypeReference* typeRef1 = new CodeTypeReference(S"System.DateTime");

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression* typeof1 = new CodeTypeOfExpression(typeRef1);

// A C# code generator produces the following source code for the preceeding example code:

//    typeof(System.DateTime);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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

CodeTypeReference Members | System.CodeDom Namespace

Show:
© 2014 Microsoft