Export (0) Print
Expand All

CodeTypeReference Class

Represents a reference to a type.

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

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

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeTypeReference : CodeObject

The CodeTypeReference type exposes the following members.

  NameDescription
Public methodCodeTypeReference()Initializes a new instance of the CodeTypeReference class.
Public methodCodeTypeReference(CodeTypeParameter)Initializes a new instance of the CodeTypeReference class using the specified code type parameter.
Public methodCodeTypeReference(String)Initializes a new instance of the CodeTypeReference class using the specified type name.
Public methodCodeTypeReference(Type)Initializes a new instance of the CodeTypeReference class using the specified type.
Public methodCodeTypeReference(CodeTypeReference, Int32)Initializes a new instance of the CodeTypeReference class using the specified array type and rank.
Public methodCodeTypeReference(String, CodeTypeReference[])Initializes a new instance of the CodeTypeReference class using the specified type name and type arguments.
Public methodCodeTypeReference(String, CodeTypeReferenceOptions)Initializes a new instance of the CodeTypeReference class using the specified type name and code type reference option.
Public methodCodeTypeReference(String, Int32)Initializes a new instance of the CodeTypeReference class using the specified array type name and rank.
Public methodCodeTypeReference(Type, CodeTypeReferenceOptions)Initializes a new instance of the CodeTypeReference class using the specified type and code type reference.
Top

  NameDescription
Public propertyArrayElementTypeGets or sets the type of the elements in the array.
Public propertyArrayRankGets or sets the array rank of the array.
Public propertyBaseTypeGets or sets the name of the type being referenced.
Public propertyOptionsGets or sets the code type reference option.
Public propertyTypeArgumentsGets the type arguments for the current generic type reference.
Public propertyUserDataGets the user-definable data for the current object. (Inherited from CodeObject.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 = 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)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft